Skip to content

Instantly share code, notes, and snippets.

@nbogie
Created November 16, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbogie/51ccac91f3e8efdc112ac811f1160319 to your computer and use it in GitHub Desktop.
Save nbogie/51ccac91f3e8efdc112ac811f1160319 to your computer and use it in GitHub Desktop.
MouseLookScript - Unity - Old input system
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