Hi everyone,
Currently I’m making a FPS game. I really want to make the camera stop going more than 90 degrees on the left and right sides. Any way to do it? Here is my code:
using UnityEngine;
using System.Collections;
public class MouseLook : MonoBehaviour
{
[Header("Data")]
public float sens;
public Transform player;
float xRotation;
public Vector2 turn;
public Vector3 deltaMove;
public float viewRange;
public float MaxRange;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
//Rotation Sensitivity
public float RotationSensitivity = 35.0f;
public float minAngle = -45.0f;
public float maxAngle = 45.0f;
//Rotation Value
float yRotate = 0.0f;
// Update is called once per frame
void Update()
{
//Rotate Y view
yRotate += Input.GetAxis("Mouse Y") * RotationSensitivity * Time.deltaTime;
yRotate = Mathf.Clamp(yRotate, minAngle, maxAngle);
transform.eulerAngles = new Vector3(yRotate, 0.0f, 0.0f);
turn.x += Input.GetAxis("Mouse X") * sens * Time.deltaTime;
turn.y = Input.GetAxis("Mouse Y") * sens * Time.deltaTime;
xRotation -= turn.y;
xRotation = Mathf.Clamp(xRotation, -90, 90f);
transform.localRotation = Quaternion.Euler(xRotation, turn.x, 0);
}
}