- Home /
OnMouseUp and GUITexture
I have the following code attached to a GameObject with a GUITexture attached, however when I click on the button, the OnMouseUp function is not called. What's wrong? As far as I can tell, the docs say this should be possible.
function Update () { //Keep button in same relative location
var width = Screen.width/13;
var height = Screen.height/9;
guiTexture.pixelInset = Rect(Screen.width-width*2, Screen.height-height*4, width, height);
}
function OnMouseUp () {//Button clicked
print("button clicked");
Application.LoadLevel(1);
}
Answer by Eric5h5 · Jun 02, 2011 at 07:18 PM
Try this: remove the Update function, do GameObject -> Create Other -> GUI Texture, then attach the script to that GUITexture. You can see that it does work. Since GUITextures use normalized viewport coords, I'd recommend just using those instead of calculating pixel insets. (And if you are going to do that anyway, there's no need to do it in Update, since the screen resolution rarely if ever changes during gameplay.)
Your answer
Follow this Question
Related Questions
NGUI: Button don't detect input if parent change position on-screen? 1 Answer
How to fire gui button on mouse right release 2 Answers
[C#] Read from a file and write in a button? 1 Answer
Centering a texture in a GUI.Button 4 Answers
GUI and buttons 3 Answers