0
votes

I want to animate a card flipping from its front face to its back face. Both card faces have different sprites as their background.

I have an Animator component attached to my card. The animator rotates the card 180 degrees around the z-axis, and changes the background sprite when it has rotated 90 degrees. That all works correctly.

The problem is that the sprite changes back to the original sprite once the animation clip is complete. I tried adding an animation event to the end of the animation clip event's function and having the animation clip do GetComponent<SpriteRenderer>().sprite = ..., but that doesn't work either. Even if I change the card's sprite in the Unity Inspector, that doesn't work (the sprite doesn't actually change).

Here's what my animator looks like (the Idle animation has no clip attached to it):

enter image description here

Here's what one of the animations looks like:

enter image description here

Is there a way that I can have my animator change my game object's sprite, and then have the game object maintain the new sprite until it is changed again? I know I can do it programmatically through a coroutine, but I don't want to do a workaround if it's not necessary.

2

2 Answers

1
votes

Afaik you just have to disable the Write Defaults value of the States

It means that if for a property there are no keyframes available in this state than use the default ones from the unanimated model (whatever you see in the editmode without being in an Animator preview).

So if you disable it this State will use whatever current property values it gets from the animations before instead of the unanimated value.