I’ve done some research this morning and can’t find an eloquent way (2 lines of code) to do this efficiently. Unfortunately, I am not that familiar with animation and the animator, so any help is appreciated.
I’ve got a sprite animation of a hexagonal loading bar with six sides. I would like to link it to the async loading progress, so that at intervals of 14.28% (of loading), the next frame of the animation plays.
This is what the code looks like for the status text (0 - 100%), which gets its value from a progress bar (which I may or may not implement visually). (This is all in update)
So, what I was thinking was maybe a line to access the animation clip and manually move the frames forward by a percentage (there are 7 frames at 0:01 intervals) linked to progressBar.value. I think that’s it really, I could set the animation time to zero to stop it from looping.
Any help greatly appreciated. I’ve got a feeling there is an extremely simple solution to this, but I just can’t seem to see it.
Moving animation frame by frame forward would be an ok option since clearly you need to control every aspect to it. You just need to calculate is progress bar moved from last frame move >= 14.28% and then move one frame and repeat.
Usually you would use animation if its some complex looking progress bar that is hard to update trough code, otherwise you can update simple bars or pies, spinners and similar things just trough code no need for animating.
Yeah, I just don’t know how to access the animation clip or how to move the frames. I’ve been through the API and I haven’t really found a function that sets the frame.
Yeah, setting the frame of an animation clip is going to be horrible. Unity’s animation system does not handle going directly to a certain time in the animation at all.
For this purpose, switching the sprites is going to be a lot easier than doing things through animation.
If you wish to jump to specific time in animation you can use:
And then to pause it would be actually setting speed to 0 of animator but that would also mean you need to confirm that animation is at time x where you want to stop it.
Now, when there is a lot to load, it slows down the animation to keep in line with the async load process. As the loading processes continues, the animation speeds up. In this way, the loading progress of the sprites will always stay in line with the loading progress of the async function.