- Home /
Can someone add comments to this? I don't understand what's happening.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CameraScript : MonoBehaviour { public float mouseSensitivity = 500.0f; public float clampAngle = 90.0f;
private float rotY = 0.0f; // rotation around the up/y axis
private float rotX = 0.0f; // rotation around the right/x axis
void Start()
{
Vector3 rot = transform.localRotation.eulerAngles;
rotY = rot.y;
rotX = rot.x;
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X"); // Mouse X Position on the screen
float mouseY = -Input.GetAxis("Mouse Y"); // Mouse Y Position on the screen
rotY += mouseX * mouseSensitivity * Time.deltaTime; // Rotation added to the mouse X, multiplied by the mouse sensitivity then delta time
rotX += mouseY * mouseSensitivity * Time.deltaTime; // Rotation added to the mouse Y, multiplied by the mouse sensitivity then delta time
rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f);
transform.rotation = localRotation;
}
}
Comment
Your answer
Follow this Question
Related Questions
Help me to avoid the camera to discover the world boundary 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Brickshooter tutorial: bounding camera movement 1 Answer
switching cameras C# 4 Answers