Created
November 16, 2021 15:22
-
-
Save nbogie/51ccac91f3e8efdc112ac811f1160319 to your computer and use it in GitHub Desktop.
MouseLookScript - Unity - Old input system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class MouseLookScript : MonoBehaviour | |
{ | |
public float lookSensitivity = 10f; | |
private float leftRightAngle = 0; | |
private float upDownAngle = 0; | |
void Start() | |
{ | |
Cursor.lockState = CursorLockMode.Locked; | |
Cursor.visible = false; | |
} | |
void Update() | |
{ | |
float hInput = Input.GetAxis("Mouse X") * lookSensitivity; | |
float vInput = -Input.GetAxis("Mouse Y") * lookSensitivity; | |
leftRightAngle += hInput; | |
upDownAngle += vInput; | |
upDownAngle = Mathf.Clamp(upDownAngle, -60, 60); | |
transform.rotation = Quaternion.Euler(upDownAngle, leftRightAngle, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment