jump to previous sprite in animation

Hi
i have created a very simple animation of photos. I am using .speed = 0 and 1 to start/stop the animation.

anim.speed = 0;
anim.speed = 1;

When the animation is paused i want to offer the ability to go back to the previous photo in the series

I have been searching for solutions but I don’t think i am searching for the correct terminology!

I basically want to do this
sprite/frame = x
moveto (sprite/frame - 1)

how do i do this?

thanks

to put it another way
I have an animation with 30 sprites. I have paused the animation at sprite 18. How do go back to sprite 17?

(also tried chat gpt but that was worse than useless!)

thanks

You could try using the Animator.Play() function.

One of the parameters is normalizedTime which tells the animator where to start the animation. In your example, you would pass in 18/30 to start at frame 18. I don’t know how this will behave if you have set the Animator speed to 0.

thank you - that has definitely set me on the right track

anim.Play("Base Layer.editPhotos", 8/14, 0.25f);

However if I am going to use this method then i need to be able to dynamically work out the current frame, ideally the total number of frames and then decrement

so it would look something like

anim.Play("Base Layer.editPhotos", (currentSprite-1)/totalSprites, 0.25f);

do you know if i am able to access those properties and if so, how?

thanks

You may be able to use GetCurrentAnimatorStateInfo to get some of the information you are looking for, but this isn’t going to tell you how many keyframes are defined for the current animation.

Are you sure that using an animator is the best option for your use case? It sounds like you need a lot of control over how and when the current sprite changes.

I’m beginning to think the same thing but seemed the easiest way to implement a simple photo frame. Will look for other options
Thanks