using UnityEngine;
using System.Collections;
public class MouseRotion : MonoBehaviour {
private Vector3 nowRotation;
private float x, y,z;
// Use this for initialization
void Start () {
nowRotation = transform.eulerAngles;
x = nowRotation.x;
y = nowRotation.y;
z = nowRotation.z;
}
// Update is called once per frame
void Update () {
x += Input.GetAxis("Mouse X") * 180 * 0.02f;
y -= Input.GetAxis("Mouse Y") * 90 * 0.02f;
y = ClampAngle(y, -130, -60);
var rotation = Quaternion.Euler(y, x, z);
transform.rotation = rotation;
}
static float ClampAngle ( float angle, float min ,float max ) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
}
沒有留言:
張貼留言