这是代码:
使用 UnityEngine;
public class playerMovement : MonoBehaviour {
public Rigidbody2D rb;
public float strength = 100f;
void Start () {
//Initialize the body of the sprite so that forces
//can be applied.
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate () {
//Note2Self: var says this is a variable of unspecified type.
var touch = new Touch();
/*
if (touch.phase == TouchPhase.Began){
rb.AddForce(transform.forward * strength);
}*/
if (Input.anyKey)
rb.position.Set(0, 100);
}
}
我正在尝试在 Unity 中练习一些基本的东西(我根本不习惯在 IDE 中编程,到目前为止,我们只是在我的程序中使用了 vim),这时我遇到了这个奇怪的问题。
首先,我不明白为什么在没有触摸识别的情况下精灵会移动,因为我还没有在移动设备上实际测试过。所以我把它注释掉了,由于某种原因,精灵仍然在移动。该代码不应该做任何事情,但它确实如此。
我已经检查了精灵是否使用了最新的脚本 - 它是 - 我已经检查了脚本是否针对正确的刚体并且它是一个刚体 2D。这是。
到底是怎么回事?
