- Home /
Show/Hide Mouse on Screen Position
I've been looking for a way for some days now here in unityAnswers(but no luck yet) to show my cursor when it is at 20pixel from top of my screen and center and hide it when it is greater than 20pixel.
Any help is greatly appreciated! Thanks!
[EDITED]
I just found a solution using the code from the Scripting manual and just added a couple of lines. Here it is if someone is interested.
private var test : GUILayer;
test = Camera.main.GetComponent(GUILayer);
function Update() { if(test.HitTest(Input.mousePosition) != null) { Debug.Log(test.HitTest(Input.mousePosition).name); Screen.showCursor = true; } else { Screen.showCursor = false; }
}
Put this code on your GUITexture. It should make your mouse cursor appear when it is hitting it. Just don't forget to apply the
Screen.showCursor = false;
on an empty GameObject or so.
Answer by efge · Apr 09, 2011 at 11:59 AM
You could define a rectangle in screen coordinates and use Rect.Contains to detect if the mouse is inside.
Thanks for the response! Can I apply this to like guiTextures which is what I want to do without creating Rect()? Where my guiTexture is always available at the top of the screen
Your answer
Follow this Question
Related Questions
Cursor track object 1 Answer
Screen.lockCursor will not work 1 Answer
screen.lockcursor locks the cursor in wrong place 1 Answer
How to make something happen when mouse on side of screen? 1 Answer
Camera Follow Mouse 2 Answers