Skip to content

Instantly share code, notes, and snippets.

@marcusx2
Last active February 26, 2024 16:51
Show Gist options
  • Select an option

  • Save marcusx2/8563e00d6fec2ecb69b2f8d6dd8d2435 to your computer and use it in GitHub Desktop.

Select an option

Save marcusx2/8563e00d6fec2ecb69b2f8d6dd8d2435 to your computer and use it in GitHub Desktop.

Revisions

  1. marcusx2 renamed this gist Sep 8, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. marcusx2 revised this gist Aug 25, 2020. No changes.
  3. marcusx2 renamed this gist Aug 25, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. marcusx2 created this gist Aug 25, 2020.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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;
    }
    }