- Home /
OnMouseDown
Im trying to get a print out of OnMouseUp/Down, OnMouseEnter/Exit none are printing anything... Am i suppose to do something special for these functions to work? I have the functions on all the GUI scripts in the game, i click hover over and whatever else i can think of, yet not a single print. The Objects who have the GUI scripts attached do no belong to Ignore Raycast Layer...I randomly got 1 print(after restarting Unity) when i started the game, no click in the editor. Im lost on this one.
On my main GUI script..
function OnMouseDown()
{
overGUI=true;
print("Down");
}
On a different GUI script
function OnMouseEnter()
{
overGUI=true;
print("Enter");
}
does the object this script is attached to have a collider ? sry , cannot help with GUI Elements
No they do not. Im trying to get it to work for GUI Elements Only. The ref says either GUIElement or Collider. Its wierd bcuz its not like its not GUI enough...i have a Window with a button in it, labels all over the place, pics rendering all over the screen. Ugh, maybe time for a comp restart...
Answer by Bunny83 · Mar 27, 2012 at 11:04 AM
Don't confuse GUIElement (GUIText, GUITexture) components with UnityGUI (OnGUI callback, GUI class, GUILayout class) these are two different things. OnMouseDown / Up / Enter / Exit works only for GameObjects with a GUIElement component attached. Those callbacks aren't called for GUI controls created in OnGUI().
Wow, i misinterpreted that completely. Thanks for the clarification. Guess i gotta figure out a new way to detect the mouse click over rendering screen gui. Now that ive had a day to think about it, it shouldnt be to bad. Thanks again.
Since all HUI controls are Rects you could use Rect.Contains to test if the mouse is over a certain control (or screen space ;) ).
Answer by zerox911 · Mar 27, 2012 at 09:04 AM
try something like this ...
var normalTex : Texture2D;
var hoverTex : Texture2D;
function OnMouseEnter () {
guiTexture.texture = hoverTex;
}
function OnMouseExit(){
guiTexture.texture = normalTex;
}
function OnMouseDown(){
Debug.Log("clicked");
}
Your answer
Follow this Question
Related Questions
OnMouseOver Problem 3 Answers
Multiple GUI textures one script 2 Answers
Text popup onMouseDown 2 Answers
Changing the Mouse's Range for OnMouse events 0 Answers
Change Font Style OnMouseEnter 0 Answers