using UnityEngine;
using System.Collections;
public class PlayerMove : MonoBehaviour {
public float moveSpeed = 2f;
public float rotateSpeed = 5f;
void Update () {
//控制物体移动按照镜头方向
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if(h!=0||v!=0)
{
Vector3 MoveDirection = new Vector3(h, 0, v);
float y = Camera.main.transform.rotation.eulerAngles.y;
MoveDirection = Quaternion.Euler(0, y, 0) * MoveDirection;
transform.Translate(MoveDirection * Time.deltaTime * moveSpeed, Space.World);
}
//镜头视角的旋转Q(左)E(又)
if(Input.GetKey(KeyCode.Q))
{
transform.Rotate(-Vector3.up * Time.deltaTime * rotateSpeed);
}
if (Input.GetKey(KeyCode.E))
{
transform.Rotate(Vector3.up * Time.deltaTime * rotateSpeed);
}
}
}
using System.Collections;
public class PlayerMove : MonoBehaviour {
public float moveSpeed = 2f;
public float rotateSpeed = 5f;
void Update () {
//控制物体移动按照镜头方向
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if(h!=0||v!=0)
{
Vector3 MoveDirection = new Vector3(h, 0, v);
float y = Camera.main.transform.rotation.eulerAngles.y;
MoveDirection = Quaternion.Euler(0, y, 0) * MoveDirection;
transform.Translate(MoveDirection * Time.deltaTime * moveSpeed, Space.World);
}
//镜头视角的旋转Q(左)E(又)
if(Input.GetKey(KeyCode.Q))
{
transform.Rotate(-Vector3.up * Time.deltaTime * rotateSpeed);
}
if (Input.GetKey(KeyCode.E))
{
transform.Rotate(Vector3.up * Time.deltaTime * rotateSpeed);
}
}
}