按照下图所示添加如下代码:
public float movespeed = 5;
public GameObject go;
if (Input.GetKey(KeyCode.W))
{
go.transform.Translate( 0, 0, movespeed * Time.deltaTime, Space.World);
}
if (Input.GetKey(KeyCode.S))
{
go.transform.Translate( 0, 0, movespeed * Time.deltaTime * (-1),Space.World);
}
if (Input.GetKey(KeyCode.A))
{
go.transform.Translate(movespeed * Time.deltaTime*(-1), 0, 0, Space.World);
}
if (Input.GetKey(KeyCode.D))
{
go.transform.Translate(movespeed * Time.deltaTime, 0, 0, Space.World);
}