Files
OMG/Assets/Scripts/CameraController.cs

38 lines
1.0 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private InputMaster _inputMaster;
[SerializeField] private float mouseSensitivity = 20f;
[SerializeField] private Transform playerBody;
private float _mouseX, _mouseY;
private float xRotation;
private void Awake()
{
_inputMaster = new InputMaster();
_inputMaster.Player.Look.Enable();
}
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
var mousevalue = _inputMaster.Player.Look.ReadValue<Vector2>();
_mouseX = mousevalue.x * mouseSensitivity * Time.deltaTime;
_mouseY = mousevalue.y * mouseSensitivity * Time.deltaTime;
xRotation -= _mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * _mouseX);
}
}