Untitled
unknown
csharp
2 years ago
1.4 kB
6
Indexable
using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.InputSystem; public class PlayerCamera : MonoBehaviour { [SerializeField] float xSens = 40f; [SerializeField] float ySens = 40f; [SerializeField] float maxAngle = 90f; [SerializeField] Transform orientation; PlayerInputActions controls; float xRotation; float yRotation; void Awake() { controls = new PlayerInputActions(); } void OnEnable() { controls.Enable(); } void OnDisable() { controls.Disable(); } void Start() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } void Update() { Look(); } void Look() { Vector2 t_mouseInput = controls.Player.Look.ReadValue<Vector2>(); float t_mouseX = t_mouseInput.x * xSens * Time.deltaTime; float t_mouseY = t_mouseInput.y * ySens * Time.deltaTime; yRotation += t_mouseX; xRotation -= t_mouseY; xRotation = Mathf.Clamp(xRotation, -maxAngle, maxAngle); transform.rotation = Quaternion.Euler(xRotation, yRotation, 0f); orientation.rotation = Quaternion.Euler(0f, yRotation, 0f); } }
Editor is loading...