Last active
February 26, 2024 16:51
-
-
Save marcusx2/8563e00d6fec2ecb69b2f8d6dd8d2435 to your computer and use it in GitHub Desktop.
Look around camera with mouse - Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class FreeCamera : MonoBehaviour | |
{ | |
public float sensitivity = 10f; | |
public float maxYAngle = 80f; | |
private Vector2 currentRotation; | |
void Update() | |
{ | |
currentRotation.x += Input.GetAxis("Mouse X") * sensitivity; | |
currentRotation.y -= Input.GetAxis("Mouse Y") * sensitivity; | |
currentRotation.x = Mathf.Repeat(currentRotation.x, 360); | |
currentRotation.y = Mathf.Clamp(currentRotation.y, -maxYAngle, maxYAngle); | |
Camera.main.transform.rotation = Quaternion.Euler(currentRotation.y,currentRotation.x,0); | |
if (Input.GetMouseButtonDown(0)) | |
Cursor.lockState = CursorLockMode.Locked; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple script to look around with the game's camera using the mouse. Useful to debug on the game view.