public float speedNormal = 10.0f;
public float speedFast = 50.0f;
public float mouseSensitivityX = 5.0f;
public float mouseSensitivityY = 5.0f;
private float rotY = 0.0f;
private float rotX = 0.0f;
private float v;
private float h;
private float speed;
private Vector3 trans;
void Start()
{
rotX = transform.localEulerAngles.y;
rotY = transform.localEulerAngles.x;
}
void Update()
{
if (Input.GetMouseButton(0))
{
rotX += Input.GetAxis("Mouse X") * mouseSensitivityX;
rotY -= Input.GetAxis("Mouse Y") * mouseSensitivityY;
transform.rotation = Quaternion.Euler(rotY, rotX, 0);
}
v = Input.GetAxis("Vertical");
h = Input.GetAxis("Horizontal");
if (v != 0.0f)
{
speed = Input.GetKey(KeyCode.LeftShift) ? speedFast : speedNormal;
trans = new Vector3(0.0f, 0.0f, v * speed * Time.deltaTime);
transform.localPosition += transform.localRotation * trans;
}
// strafe left/right
if (h != 0.0f)
{
speed = Input.GetKey(KeyCode.LeftShift) ? speedFast : speedNormal;
trans = new Vector3(h * speed * Time.deltaTime, 0.0f, 0.0f);
transform.localPosition += transform.localRotation * trans;
}
}
网友评论