- Home /
Question by
cristeatudor6 · Aug 15, 2020 at 08:39 AM ·
ui2d gamemask
Need help with health bar
Hello. I have a problem. I have a health bar and a mask that works with it, but the health goes from right to left and I want it to go from left to right as it decreases. I will attach an image of the script and a link for a video of the visual problem. If anyone has any ideas please let me know.
screenshot-1.png
(120.8 kB)
Comment
Best Answer
Answer by Hellium · Aug 15, 2020 at 09:03 AM
void Start()
{
originalSize = mask.rectTransform.anchorMax.x - mask.rectTransform.anchorMin.x;
}
public void SetValue(float value)
{
Vector2 anchorMin = mask.rectTransform.anchorMin;
anchorMin.x = mask.rectTransform.anchorMax.x - ( 1 - value ) * originalSize;
mask.rectTransform.anchorMin = anchorMin;
}
Note: Please, next time, provide your code as text