美文网首页
FPS的camera

FPS的camera

作者: 自由的天空 | 来源:发表于2016-04-14 21:38 被阅读36次

    public enum RotationAxes    {        MouseXAndY = 0,        MouseX = 1,        MouseY = 2    }  

      public RotationAxes axes = RotationAxes.MouseXAndY;  

      public float sensitivityHor = 9.0f;   

     public float sensitivityVert = 9.0f;  

      public float minimumVert = -45.0f;    

    public float maximumVert = 45.0f; 

       private float _rotationX = 0;    

    void Start()    {    

    Rigidbody body = GetComponent<Rigidbody>();

    if (body != null)

    body.freezeRotation = true;

    }

    void Update()

    {

    if (axes == RotationAxes.MouseX)

    {

    transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityHor, 0);

    }

    else if (axes == RotationAxes.MouseY)

    {

    _rotationX -= Input.GetAxis("Mouse Y") * sensitivityVert;

    _rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);

    float rotationY = transform.localEulerAngles.y;

    transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);

    }

    else {

    _rotationX -= Input.GetAxis("Mouse Y") * sensitivityVert;

    _rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);

    float delta = Input.GetAxis("Mouse X") * sensitivityHor;

    float rotationY = transform.localEulerAngles.y + delta;

    transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);

    }

    }

    相关文章

      网友评论

          本文标题:FPS的camera

          本文链接:https://www.haomeiwen.com/subject/gtixlttx.html