- Home /
How do I change the size of a UI Image? (Javascript)
I've been looking for some answers for this forever.. All the things I find are in C# Id want to re-size the image for my health bar, please help!
Firstly it depends on "how u created the image". If u did it by using the old gui, u could simple integrate Screen.width and Screen.height in your rect definitions. Then the healthbar will be resized depending on your screensize. (sorry, also using C#)
well the image is an object in the canvas, you know? its not scripted
Yes. I think u have to pull therefore the objects rect.transform.width and rect.transform.witdh
But I'm not 100% sure. I'm using the old gui
references with which u work: http://docs.unity3d.com/$$anonymous$$anual/class-RectTransform.html
Then u have to get the component by doing this:
RectTransform transf = GameObject.Find("nameofGameobjectwithrecttransform").GetComponent<RectTransform>();
in case of C# is it that, I think.
then u can edit width and height by doing that:
transf.rect.width and transf.rect.height
Your answer
Follow this Question
Related Questions
Change size of an UI object ( Javascript ( Unityscript) ) 0 Answers
UI resizing in game 1 Answer
Guilayout problems with image resize 0 Answers
Animate Image UI with Sprite Sheet 4 Answers
Unity 5.0 Trying to Change the Image - Source Image via Script 3 Answers