using System.Collections; using System.Collections.Generic; using UnityEditor.Experimental.GraphView; using UnityEngine; public class CameraLook : MonoBehaviour { [Header("Reference")] [SerializeField] private Rigidbody rb; [SerializeField] Transform Camera; [SerializeField] private Transform camHolder; [Space] [Header("Mouse Settings")] [SerializeField] private float mouseSensitivity; [SerializeField] private float minXRotation; [SerializeField] private float maxXRotation; private float mouseX; private float mouseY; float xRotation; private void Start() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } private void Update() { // Custom Functions ONLY > For Clean Code & Readability Purposes!!\\ HandleInput(); HandleCamRotation(); } private void FixedUpdate() { // Custom Functions ONLY > For Clean Code & Readability Purposes!!\\ HandleRbRotation(); } private void HandleRbRotation() // Completed \\ { // Rotate rigidbody here!! \\ // consume the accumulated input here Quaternion rotationToAdd = Quaternion.Euler(0, mouseX, 0); // we're consuming all the accumulated input so let's zero out the variable mouseX = 0; Quaternion newRotation = rb.rotation * rotationToAdd; rb.MoveRotation(newRotation); } private void HandleInput() //Completed\\ { // accumulate mouse input here \\ mouseX += Input.GetAxis("Mouse X") * mouseSensitivity; mouseY += Input.GetAxis("Mouse Y") * mouseSensitivity; } private void HandleCamRotation() //Completed\\ { // Apply rotation xRotation -= mouseY; xRotation = Mathf.Clamp(xRotation, minXRotation, maxXRotation); Camera.localRotation = Quaternion.Euler(xRotation, 0, 0); // Reset accumulated input mouseY = 0; } }