大家好,我开始学习Unity游戏引擎和C#,我一步一步地学习视频课程,但当我按下播放按钮时,它会立即居中游戏对象,当我试图移动它时,它会移动,但总是返回中心(位置0,0,0)
public class PlayerMovment : MonoBehaviour
{
public float speed = 5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector2 pos = transform.position;
pos.x = h * speed * Time.deltaTime;
pos.y = v * speed * Time.deltaTime;
transform.position = pos;
}
}
1条答案
按热度按时间6l7fqoea1#
您需要将您的移动“添加”到该位置,而不是覆盖它。请尝试以下操作: