- Home /
Image dissappearing when assigning fill amount
Hello,
I have a standard circular "ammo bar" under my UI canvas that i want to track and follow the amount of ammo i have left defined in my gamemaster script
The problem is that once I fire, subtracting the ammo by 1... the fill amount goes to 0 and the image dissapears. I've checked the math, and debugged the values in realtime... they print fine... but for some reason the fill amount just goes to zero once i fire the first bullet. Heres my code applied to directly to the image under canvas:
public static Image ammoCounter;
private GameObject gm;
void Start () {
ammoCounter = GetComponent<Image>();
gm = GameObject.FindGameObjectWithTag("gamemaster");
}
void FixedUpdate () {
ammoCounter.fillAmount = gm.GetComponent<gamemaster>().foodAmmo / 50;
print(gm.GetComponent<gamemaster>().foodAmmo);
}
}
my food ammo value in gamemaster is assigning fine... I assign it to 50 in the inspector.
Any help?
Your answer
Follow this Question
Related Questions
Image.enable not working properly 1 Answer
Change the button target image alpha 1 Answer
Instantiated UI objects with image components not appearing, rest of object works fine. 0 Answers
Get Mouse Position on an IMAGE (UI)? 1 Answer
Unity 5.0 Trying to Change the Image - Source Image via Script 3 Answers