【发布时间】:2020-03-17 03:45:09
【问题描述】:
我是第一次观看有关制作 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#”,我没有看到其他人有同样的问题。
任何帮助表示赞赏:)
【问题讨论】:
-
FixedUpdated在哪里调用? -
应该是
FixedUpdate