Search Unity

Question when I hit play the mouse cursor automaticly gets set to 90 degree.

Discussion in 'Input System' started by Bread_Ackerman, Feb 8, 2023.

  1. Bread_Ackerman

    Bread_Ackerman

    Joined:
    Jan 27, 2020
    Posts:
    1
    i have been trying different things and i cant for the life of me understand how this issue can be solved. also i am a beginner if it helps.
    here is the code (yes i did a little bit of stealing)
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. public class CameraScript : MonoBehaviour
    7. {
    8.     public float mouseSensitity = 50f;
    9.     public Transform player;
    10.     float xRotation = 0f;
    11.     private void Start()
    12.     {
    13.         Cursor.lockState = CursorLockMode.Locked;
    14.     }
    15.     void Update()
    16.     {
    17.         float mouseX = Input.GetAxis("Mouse X")*mouseSensitity*Time.deltaTime;
    18.         float mouseY = Input.GetAxis("Mouse Y")*mouseSensitity*Time.deltaTime;
    19.  
    20.         xRotation -= mouseY;
    21.         xRotation = Mathf.Clamp(xRotation, -90f, 90f);
    22.  
    23.         transform.localRotation = Quaternion.Euler(xRotation,0f,0f);
    24.         player.Rotate(Vector3.up*mouseX);                           //moves the entire body along the x axis
    25.      
    26.  
    27.     }
    28. }
    29.