Hello !
I want lock a Mouse Axis, but i dont know wath is the best way for it.
My first idea was is to use a bool for xRotation to set it true or false.
But that dosnt work becouse i have a float operator.
The next think is an if query?
What is the right way ?
Thx community!
Here is the Code
using System;
using UnityEngine;
public class PlayerLook : MonoBehaviour {
[Header("References")]
[SerializeField] private Transform cameraHolder;
[SerializeField] private Transform orientation;
[Header("Look Settings")]
[SerializeField] private float sensX = 10f;
[SerializeField] private float sensY = 10f;
private float yRotation;
private float xRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
float mouseX = Input.GetAxisRaw("Mouse X") * 0.1f;
float mouseY = Input.GetAxisRaw("Mouse Y") * 0.1f;
yRotation += mouseX * sensX;
xRotation -= mouseY * sensY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
orientation.rotation = Quaternion.Euler(0f, yRotation, 0f);
cameraHolder.localRotation = Quaternion.Euler(xRotation, yRotation, 0f);
}
}