【发布时间】:2020-07-24 16:15:13
【问题描述】:
我有一个我写的小游戏,其中我有一个向前移动和左右转动的物体。当用户按下 A 对象向左旋转如果用户按下 D 它向左旋转并向左旋转,我在用户放开键后将旋转设置为 0
bool slowbtn = Input.GetKey("s");
bool right = Input.GetKey("d");
if (right == true)
{
rd.AddForce(sideForce * Time.deltaTime, 0, 0,ForceMode.VelocityChange);
rd.transform.eulerAngles = new Vector3(0, 10 , 0);
}
if (Input.GetKey("a"))
{
rd.AddForce(-sideForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
rd.transform.eulerAngles = new Vector3(0, -10 , 0);
}
如果我想在用户释放键时将旋转设置回 0 我正在使用这个
if (Input.GetButtonUp("a"))
{
rd.transform.eulerAngles = new Vector3(0, 0, 0);
}
if (Input.GetButtonUp("d"))
{
rd.transform.eulerAngles = new Vector3(0, 0, 0);
}
但它不起作用,我不明白为什么,它还破坏了我以前的代码,所以如果不继续前进,请反对
【问题讨论】: