- Home /
UI Animation not playing/updating?
Hey, i have a UI image setup like this:
The animation makes it slide form the right to the left, and setting the "fill amount" from 1 to 0.
When I play the animation in the scene view it works like it should, but in the play mode it doesn't animate at all, I can see that the "fill amount" value is decreasing in play mode, but the image wont move. Anyone know what i could do to fix this?
This is how I play the animation:
stopwatchSlider.gameObject.GetComponent<Image> ().enabled = true;
stopwatchSlider.gameObject.GetComponent<Animation> ().enabled = true;
stopwatchSlider.animation.Play ("stopwatchSlider");
Im not sure why but with the "Animation" Component it does not work. Using the "Animator" Component it works fine.
Okay but thats weird because ive been able to use the animation component before with UI :/ but thanks i will try the animator
Hey i think i solved this by using the "Animator" ins$$anonymous$$d of "Animation" but i dont really remember , and i am from Sweden! :D
It's funny, I encountered with this on a game jam. I didn't have much time but I discovered that disabling and re-enabling UI elements in the inspector would actually update them correctly with animation. But it would update only the current frame when it got re-enabled, it still would not play. So I just added this 2 lines in update:
uiElement.enabled = false; uiElement.enabled = true;
it worked, I know it was a crappy solution but Jam was ending so I didn't care :D