Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Cursor Button Lock and Area limitation

using UnityEngine;
public class CursorScript : MonoBehaviour
{
    void Update()
    {
        //Press the space bar to apply no locking to the Cursor
        if (Input.GetKey(KeyCode.Space))
            Cursor.lockState = CursorLockMode.None;
    }

    void OnGUI()
    {
        //Press this button to lock the Cursor
        if (GUI.Button(new Rect(0, 0, 100, 50), "Lock Cursor"))
        {
            Cursor.lockState = CursorLockMode.Locked;
        }

        //Press this button to confine the Cursor within the screen
        if (GUI.Button(new Rect(125, 0, 100, 50), "Limited Cursor"))
        {
            Cursor.lockState = CursorLockMode.Confined;
        }
    }
}
 
PREVIOUS NEXT
Tagged: #Cursor #Button #Lock #Area #limitation
ADD COMMENT
Topic
Name
2+9 =