赞
踩
一、使用轴
public class Move : MonoBehaviour {
public float MoveSpeed;
public float RotoSpeed;
void Update ()
{
//方向轴的名字可以在Edit\project settings\input中修改
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
transform.Translate(new Vector3(0,0,ver * Time.deltaTime * MoveSpeed));
transform.Rotate(new Vector3(0, hor * Time.deltaTime * RotoSpeed, 0));
}
}
二、设置方向键
public float MoveSpeed;
public float RotoSpeed;
void Update ()
{
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
if(Input.GetKey(KeyCode.W)||Input.GetKey(KeyCode.UpArrow))
{
transform.Translate(new Vector3(0, 0, 1) * MoveSpeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.S)||Input.GetKey(KeyCode.DownArrow))
{
transform.Translate(new Vector3(0, 0, -1) * MoveSpeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.A)||Input.GetKey(KeyCode.LeftArrow))
{
transform.Rotate(new Vector3(0, -1, 0) * RotoSpeed * Time.deltaTime);
}
if(Input.GetKey(KeyCode.D)||Input.GetKey(KeyCode.RightArrow))
{
transform.Rotate(new Vector3(0, 1, 0) * RotoSpeed * Time.deltaTime);
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。