-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseLook.cs
More file actions
31 lines (27 loc) · 922 Bytes
/
MouseLook.cs
File metadata and controls
31 lines (27 loc) · 922 Bytes
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
private PlayerMovement pm;
public float sensitivity = 100f;
public Transform playerbody;
private float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
//pm = GameObject.FindObjectOfType<PlayerMovement>();
//pm.walkingSpeed = 25f;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerbody.Rotate(Vector3.up * mouseX);
}
}