animation["HandsUp"].wrapmode = WrapMode.Once help

Hey guys - I got a problem. I’m using a work around to make it work, but I want to know what other people suggest.

I’m using a C# Enum to set the status of my AI, when the AI is ordered to put the hands up, even using animation[“HandsUp”].wrapmode = WrapMode.Once, then using crossfade to play, the animation will repeat.

A debug in the status log of HandsUp Enum shows that its going over, and over and over as expected - and thus the animation keeps playing over, and over - I restarted Unity as sometimes these odd ball problems happen from that - I also set the animation default to ONCE and tried this method - however, the animation does play once, and then is recalled…

To stop this - I setup a bool, “playOnce” - the character will do the animation once, as intended - and when the AI state returns to normal playOnce is reset for another use.

The main problem I’m having is I’m using this bool for each status (handsup, request id) so when multiple requests come into play of course the animation will not play a second time (hands up will play, but if I order to give ID after hands up, it won’t play because playOnce is now false)…

Now I could set a bool for each status, then reset them when they return to normal - but then say if the player tells AI to put his hands up, then requests ID, then returns to the hands up status for whatever reason - this again wouldn’t trigger unless I reset ALL the bools within each status except the one I’m currently in. I was wondering if anyone had a better solution for this situation?

Not asking for code as always, just logic I guess.

If someones confused as to what I’m asking I’ll provide code when I get home, I’m confused reading it and I know what I’m asking… 0.0

I’d guess that it is playing only once, but your code is telling it to play again. A play/crossfade is ignored if already playing, so easy to call Play every frame and not realize it.

But, you can set wrapMode in the Inspector. Or can set it in code just once in Start. You rarely have an animation that makes sense to sometimes loop and sometimes play once, so setting the wrapmode once makes sense. That can make the rest of the logic easier.