unity控制物体移动
作者:互联网
public float moveSpeed = 5.0f;
void Update()
{
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.up * Time.deltaTime * moveSpeed);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(Vector3.down * Time.deltaTime * moveSpeed);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.left * Time.deltaTime * moveSpeed);
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * Time.deltaTime * moveSpeed);
}
}
标签:Translate,物体,Vector3,transform,moveSpeed,unity,Input,移动,KeyCode 来源: https://www.cnblogs.com/Zigzag37/p/16084030.html