x


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);
}
more ▼

asked Jun 02 '11 at 07:00 PM

qwertyp gravatar image

qwertyp
164 14 15 21

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.)

more ▼

answered Jun 02 '11 at 07:18 PM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3811
x819
x33

asked: Jun 02 '11 at 07:00 PM

Seen: 1215 times

Last Updated: Jun 02 '11 at 07:18 PM