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