コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (player.isAlive() && player.inControl)
        {
            //Resets the average rotation
            rotAverageY = 0f;
            rotAverageX = 0f;

            //Gets rotational input from the mouse
            rotationY += (Input.GetAxis("Mouse Y") * sensitivity) * 100 * Time.deltaTime;
            rotationX += (Input.GetAxis("Mouse X") * sensitivity) * 100 * Time.deltaTime;

            rotationY = Mathf.Clamp(rotationY, -90, 90);

            //Adds the rotation values to their relative array
            rotArrayY = rotationY;
            rotArrayX = rotationX;

            //Adding up all the rotational input values from each array

            rotAverageY += rotArrayY;
            rotAverageX += rotArrayX;


            //Get the rotation you will be at next as a Quaternion
            Quaternion yQuaternion = Quaternion.AngleAxis(rotAverageY, Vector3.left);
            Quaternion xQuaternion = Quaternion.AngleAxis(rotAverageX, Vector3.up);

            //Rotate
            transform.localRotation = originalRotation * yQuaternion;
            playerMM.rotatePlayer(xQuaternion);
        }
    }