x


Change GUI button position in code

Hey,

So I want to have the position of my button change once the user has clicked it. I'm not sure how to do this and haven't found anything yet on the forums, answers, or documentation. I know I setup the GUI button with GUI.Button(Rect(ect. But How can I tell the button to change location?

Thanks!

more ▼

asked Aug 02 '11 at 03:06 PM

zachypin gravatar image

zachypin
71 35 38 38

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

1 answer: sort voted first

After countless tries I figured I'd try the duh one for kicks and giggles, figuring it'd absolutely not work because it's too simple.... Yeah it worked.

ItemRect.x = #;

That'll change the x location of your button. You can use that for scaling the objects as well.

Edit: More code for ya since you asked.

Rect myPosition = new Rect(0,0,1,1);
void OnGUI()
{
     if(GUI.Button(myPosition), "Move me")
     {
          myPosition = new Rect(10,10,10,10);
     }
}
more ▼

answered Aug 02 '11 at 04:29 PM

zachypin gravatar image

zachypin
71 35 38 38

Could you post the full code? I am having issues with this myself.

Jul 02 '12 at 11:42 PM franktrog

Do you want to move the button to a random location each time, or a precise new location?

Do you mind posting what you had, for posterity? And for future people with similar problems?? thanks man!

Jul 02 '12 at 11:48 PM the_Simian
(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:

x3681
x885
x786
x379
x50

asked: Aug 02 '11 at 03:06 PM

Seen: 1853 times

Last Updated: Jul 03 '12 at 03:54 PM