Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

check if mouse is in frame unity

// If you want to hide the mouse when it is in frame, use this:

var mouseLocation = Camera.current.ScreenToViewportPoint(Input.mousePosition);
        var outOfFrame = Mathf.Min(mouseLocation.x, mouseLocation.y) < 0 ||
                         Mathf.Max(mouseLocation.x, mouseLocation.y) > 1;
        UnityEngine.Cursor.visible = outOfFrame;

// If you want to prevent the mouse from leaving frame:

UnityEngine.Cursor.lockCursor = true;
 
PREVIOUS NEXT
Tagged: #check #mouse #frame #unity
ADD COMMENT
Topic
Name
8+1 =