Unity of study notes (mouse movement control camera movement)

the using UnityEngine; 

public  class MouseLook: MonoBehaviour { 

    public  enum RotationAxes MouseXAndY = { 0 , MouseX = . 1 , MouseY = 2 } // define an enumeration, a mobile xy, or just moved x, or Y 
    public RotationAxes = RotationAxes.MouseXAndY axes;                  // declare an enumeration, conveniently modified shift mode outside 
    public  a float sensitivityX = 15f;                                     // define a moving velocity 
    public  a float sensitivityY = 15f; 

    public  a float minimumY = -60f;        // define a top lowest value, this value is recommended, or else will be turned
    public  a float maximumY = 60F;         // define a top highest value, this value is recommended, or else will be turned to 

    a float rotationY = 0F;                // store the actual rotation value Y 

    void the Start () 
    { 

    } 
    void the Update () 
    { 
        Switch (axes)                // determines that the user is rotatably 
        {
             Case RotationAxes.MouseXAndY:
                 a float the rotationX + = transform.localEulerAngles.y Input.GetAxis ( " Mouse X- " ) * sensitivityX; 

                rotationY + = Input.GetAxis ( " Mouse the Y ") * sensitivityY; //
                rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);

                transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
                break;
            case RotationAxes.MouseX:
                transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
                break;
            case RotationAxes.MouseY:
                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
                rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);

                transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
                break;
            default:
                break;
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/takanashi/p/11028423.html