-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseLook.cs
More file actions
44 lines (35 loc) · 1.09 KB
/
MouseLook.cs
File metadata and controls
44 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public Transform Player;
public float MouseSens = 10;
public float x = 0;
public float y = 0;
public Transform orientation;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
//INPUT
y += Input.GetAxis("Mouse X") * MouseSens;
x -= Input.GetAxis("Mouse Y") * MouseSens;
//CLAMPING
x = Mathf.Clamp(x, -90, 90);
//ROTATION
transform.localRotation = Quaternion.Euler(x, 0, 0);
orientation.transform.localRotation = Quaternion.Euler(0, y, 0);
//CURSOR
if (Input.GetKeyDown(KeyCode.Escape)&& Cursor.lockState == CursorLockMode.Locked)
{
Cursor.lockState = CursorLockMode.None;
}
else if (Input.GetKeyDown(KeyCode.Escape) && Cursor.lockState == CursorLockMode.None)
{
Cursor.lockState = CursorLockMode.Locked;
}
}
}