U3d中键盘控制移动

2020-06-16  本文已影响0人  春木杏子

U3d中如何用键位控制物体移动呢?(仅供参考)
void Update()
{
if (Input.GetKey(KeyCode.W)) //使用w移动
{
this.gameObject.transform.Translate(new Vector3(0, 0, 0.3f));
}

    if (Input.GetKey(KeyCode.A))//使用A移动
    {
        this.gameObject.transform.Translate(new Vector3(-0.3f, 0, 0));

    }

    if (Input.GetKey(KeyCode.S))//使用s移动
    {
        this.gameObject.transform.Translate(new Vector3(0, 0, -0.3f));
    }
    if (Input.GetKey(KeyCode.D))//使用D移动
    {
        this.gameObject.transform.Translate(new Vector3(0.3f, 0, 0));
    }




}
上一篇下一篇

猜你喜欢

热点阅读