public float speed=10;
float rotSpeed = 5;
void Start()
{
}
void Update()
{
float Horz = CrossPlatformInputManager.GetAxis("Horizontal");
float vert = CrossPlatformInputManager.GetAxis("Vertical");
Quaternion yrot = Quaternion.Euler(0, rotSpeed* Horz*Time.deltaTime, 0);
transform.rotation *= yrot;
transform.position += transform.forward *vert *speed *Time.deltaTime;}
方法二 charactercontroller
public float speed=10; float rotSpeed = 5;
CharacterController thisCharacter;
void Start() { t
hisCharacter = this.GetComponent();
}
void FixedUpdate()
{
float Horz = CrossPlatformInputManager.GetAxis("Horizontal");
float vert = CrossPlatformInputManager.GetAxis("Vertical");
if (Horz != 0)
{
Quaternion yrot = Quaternion.Euler(0, rotSpeed * Horz * Time.deltaTime, 0);
transform.rotation *= yrot;
}
thisCharacter.SimpleMove(transform.forward * vert * speed );
}
网友评论