Advertisement
JaspidiceYT

Cursor lock unity c# script

Apr 11th, 2021
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Cursorhide : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10.  
  11. }
  12.  
  13. // Update is called once per frame
  14. void Update()
  15. {
  16. //Thanks for watching!
  17. //created by JaspiDiceYT
  18. //Also you can change the buttons to lock and unlock
  19.  
  20. //Hides and locks cursor
  21. if (Input.GetKeyDown("1"))
  22. {
  23. Cursor.visible = false;
  24. Cursor.lockState = CursorLockMode.Locked;
  25. }
  26.  
  27. //unhides and unlocks cursor
  28. if (Input.GetKeyDown("2"))
  29. {
  30. Cursor.visible = true;
  31. Cursor.lockState = CursorLockMode.None;
  32. }
  33. }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement