TheMuseumProject/Assets/Scripts/Player/Movement/MouseLook.cs

47 lines
1.4 KiB
C#
Raw Normal View History

using UnityEngine;
namespace Player.Movement
{
public class MouseLook : MonoBehaviour
{
[SerializeField] public float mouseSensitivity = 100f;
public float xRotation;
private Transform playerBody;
// Start is called before the first frame update
private void Start()
{
// check playerprefs for sensitivity
// if not set, set to 100
// if set, set to playerprefs
if (!PlayerPrefs.HasKey("Sensitivity"))
{
PlayerPrefs.SetFloat("Sensitivity", 100f);
}
else
{
mouseSensitivity = PlayerPrefs.GetFloat("Sensitivity");
}
playerBody = transform.parent;
Cursor.lockState = CursorLockMode.Locked;
//mouseSensitivity = PlayerPrefs.GetFloat("Sensitivity");
}
// Update is called once per frame
private void Update()
{
var mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
var mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
playerBody.Rotate(Vector3.up * mouseX);
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
}
}