Changing a RectTransforms sizeDelta doesnt work while playing but after stopping
Hi there,
i try to make a very simple energy bar...like a healthbar for the players energy. I have a healthbar which works no problem (is on the player - over it) but for the energy bar which is in the PlayerUI canvas it doesnt work. The strange thing is, the bar doesnt change during the game but it (the prefab) is changed after i close the game (press the stop button).
public void UpdateEnergyBar(float _currentEnergy, float _maxEnergy)
{
float _percent = _currentEnergy / _maxEnergy;
foreground.sizeDelta = new Vector2(foreground.sizeDelta.x, maxEnergyBar * _percent);
}
the code is on an UI Image (atm the energybar is the child of this image) should work like a charm shouldnt it? Any suggestions?
Your answer
![](https://koobas.hobune.stream/wayback/20220612083251im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UI problems 0 Answers
How can I get the click position on a Rawimage ui element? 0 Answers
How to Keep 3d game object like(Cube) in place of RawImage?? 1 Answer
Can I use unity UI image in the ARKIT ? 0 Answers
C# script, Image Resolutions 0 Answers