c# - Unity没有运行基本脚本
问题描述
我是第一次观看有关制作 2d、自上而下游戏的教程的程序员。该教程稍有过时,但只有几年的时间,所以我认为它会起作用。我对这段特定代码的目标只是让玩家在按下 A 时向左看,在按下 D 时向右看。现在,什么都没有发生,但我在控制台中看不到任何错误。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
private BoxCollider2D boxCollider;
private Vector3 moveDelta;
private void Start()
{
boxCollider = GetComponent<BoxCollider2D>();
}
private void FixedUpdated()
{
float x = Input.GetAxisRaw("Horizontal");
float y = Input.GetAxisRaw("Vertical");
//Reset moveDelta
moveDelta = new Vector3(x, y, 0);
//Swap sprite direction for left or right
if (moveDelta.x > 0)
transform.localScale = Vector3.one;
else if (moveDelta.x < 0)
transform.localScale = new Vector3(-1, 1, 1);
}
}
我的 Unity 设置是否错误,或者我的代码中是否有错误?
我正在关注的教程是在 Udemy 上“通过创建真正的自上而下 RPG 来学习 Unity 引擎和 C#”,我没有看到其他人有同样的问题。
任何帮助表示赞赏:)
解决方案
推荐阅读
- php - 如何在 WordPress 中找到现有小部件的 ID?只有当小部件出现在前端时我才需要运行一个函数
- javascript - nginx和奇偶校验的Websocket连接?
- excel - 在大型 Excel 文档中查找数据以便稍后与找到的其他数据一起使用的参数
- r - 允许引用具有索引和名称的列的函数
- jenkins - Jenkins 代理作为 Jenkins 管道中阶段级别的变量
- python - python:包含对 lambda 函数的引用的导入全局变量的状态
- sql - 删除列名中带引号的列
- node.js - values 必须是一个以值名作为键的对象
- sql-server - 有关 SQL Server 2016 SP1 上 AlwaysOn 复制的问题
- javascript - 为什么状态没有被解析为 nextjs 中的变量