- Home /
Resize UI Button via Script
Hello
I can't seem to find any answer on how to resize a UI button via a script. I've been looking for an answer for a few days but I couldn't find anything. I am trying to resize them based on the resolution. I know how to resize them based on resolution and all that but the only thing I can't seem to find is how to access the button size.
Answer by RudyTheDev · Dec 04, 2014 at 02:47 PM
Change size of the new UI rect transform using scripts
Presumably, yourButton.image.rectTransform.sizeDelta = new Vector2(x, y)
where Button yourButton
with image
as referenced in inspector.
Answer by Nomabond · Dec 04, 2014 at 02:52 PM
Changing the dimensions of your buttons and UI elements via script is one way to make a responsive UI, but you can also accomplish this task much easier using the new Anchor system with Unity 4.6's new UI.
Here is a guide on creating a Responsive Menu in Unity 4.6
And here is the official documentation on Designing UI for Multiple Resolutions
Your answer
Follow this Question
Related Questions
How to make a Hover event on GUI.Button 6 Answers
Number 0 not showing up in GUI.Button 2 Answers
GUIButton Standard Texture? 1 Answer
GUILayout.Button jitters on Application.Quit (mobile) 0 Answers
GUI destroy instantiated Objects 2 Answers