Advertisement
dronkowitz

CameraController (Learning Unity)

Aug 15th, 2022
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraController : MonoBehaviour
  6. {
  7.     public Transform target;
  8.     private float xRot;
  9.     public float mouseSensitivityX = 100f;
  10.     public float mouseSensitivityY = 100f;
  11.     public Transform cam;
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.        
  16.     }
  17.  
  18.     private void Update()
  19.     {
  20.         transform.Rotate(Vector3.up * Input.GetAxis("Mouse X")* mouseSensitivityX * Time.deltaTime);
  21.         xRot -= Input.GetAxis("Mouse Y") * mouseSensitivityY * Time.deltaTime;
  22.         xRot = Mathf.Clamp(xRot, -10, 15);
  23.         cam.localRotation = Quaternion.Euler(xRot, 0, 0);
  24.     }
  25.  
  26.     // Update is called once per frame
  27.     void LateUpdate()
  28.     {
  29.         transform.position = target.position;
  30.         //transform.rotation = target.rotation;
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement