- Home /
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!
Answer by zachypin · Aug 02, 2011 at 04:29 PM
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);
}
}
Could you post the full code? I am having issues with this myself.
Do you want to move the button to a random location each time, or a precise new location?
Do you $$anonymous$$d posting what you had, for posterity? And for future people with similar problems?? thanks man!
Your answer
Follow this Question
Related Questions
GUI Button and a gameObject's position 3 Answers
Change Text of GUI Button from Script 2 Answers
Change scripted gui text postion 0 Answers