- Home /
UI 4.6: custom anchors breaking sizeDelta
Hello,
I am implementing a Time Remaining bar and would like to display it as a health bar.
I have the following values:
time left
max time (if you refill on time, you cannot go beyond this max)
scale (obtained from RectTransform.rect.width, the healthbar's width on the display)
In order to resize the bar to the proper value, I do:
remaining = timeLeft / maxTime * scale
my remaining time is decreased as Time.deltaTime. Finally, i set sizeDelta = new Vector2(remaining, someHeight)
and this works perfectly fine.
The problem arises when I change my anchors from, say, top center, to a custom one where my anchors are positioned on my corners. This is done to support proper resizing of UI elements across various screen resolutions.
The moment I change this, my health bar is more than twice the width and height than it was a moment ago.
I also notice that changing sizeDelta to:
sizeDelta -= new Vector(1, 0)
the health bar now has at least almost normal height, and the width is decreasing at the rate of 1 / frame.
Can anyone explain to me what's going on here? Am I missing something regarding sizeDelta?
Thanks!
Your answer
Follow this Question
Related Questions
[4.6 2D] Making UI image stick to the side 1 Answer
Get height and width of gameobject set with anchors 0 Answers
Create Dynamic buttons with info and update in new Unity 4.6 UI 1 Answer
Incorrect RectTransform width value when trying to read child RectTransform width. 0 Answers
Unity 4.6 UI - How to left-align scroll rect content 3 Answers