TheGuestGamez

Unity First Person Look Camera

Nov 6th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraRotateScript : MonoBehaviour
  6. {
  7. // change the name above to your script name
  8. private float x;
  9. private float y;
  10. public float sensitivity = -1f;
  11. private Vector3 rotate;
  12.  
  13. // put this script on your camera then it should work!
  14.  
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. Cursor.lockState = CursorLockMode.Locked;
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update()
  23. {
  24. y = Input.GetAxis("Mouse X");
  25. x = Input.GetAxis("Mouse Y");
  26. rotate = new Vector3(x, y * sensitivity, 0);
  27. transform.eulerAngles = transform.eulerAngles - rotate;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment