- Home /
The question is answered, right answer was accepted
Manually Programming width of new GUI
Does anyone know what the line of code is (if there is one yet) to manually adjust a new GUI object's width/left value? i would like to try and make a simple HP bar while retaining the same layout sizes for every resolution (the beauty of the new GUI). I'm still new to unity, so i'm trying to get used to everything still. Thank you!
Answer by fafase · Sep 14, 2014 at 06:49 AM
You should look at the anchor system which actually rescale based on different ratio. As we have been using it, it seems to not work entirely perfect but at least for most cases.
Otherwise you would have to access the RectTransform and start modifying the values from there with anchorMin/Max and sizeDelta.
I have been using the anchors which actually work quite well for me(and is really fun to experiment with). The issue came in where the HP bar's width has to be resized when you have less HP (i.e. half the bar when the player has half the max HP). But thank you for giving me those variables, that definitely is what i was looking for. (the only thing is what the physical line of code looks like to change those variables)
Just like any other:
RectTransform rt = GetComponent<RectTransform>();
rt.sizeDelta = new Vector2(valueX, valueY);
that's perfect thank you so much for your help!! that answers everything :).
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
GUILabel wider than Rect width 1 Answer
Multiple direction slider thing 1 Answer
Custom script editor (good practices), 0 Answers
Making GUI.Label appear for a win screen 0 Answers