Start animator with random time or delay

Hello!

I have variations from my character, say 2 or 3, and all of them have the same animator. What I’d like to do is to have them start the animations at random time / or with delay, so they are not all synchronised. How could I achieve that?

Thanks.

Could disable animator component by default,
then in the script Start(), enable the component after random wait delay…

(not tested)

This is what I just did, but not having the character moving with the animator is delaying is not an option. The thing that comes to mind is having different idle animations, and add randomisation… Any thoughts?

You can change the time of the current state in your Start() function

void Start()
{
    
    animator.Play(0,-1, Random.value);
}
8 Likes

Ok all seems pretty easy ?
but does not work ?

Looking for simple code, Unity example not really working either

Want to start animation with some delay

it appears the order of information for Anamator.Play is (animation to play name ?, 0 (for some reason), delay)

Seeing my sprite has an animation I am guessing there is a way for the software to fill the animation name with a little code.

This could be achieved either with a delayed invoke, or with a coroutine. You may have to stop your animation through code on start.

float delay = 1;
void Start()
{
Invoke("PlayAnimation", delay);
}

void PlayAnimation()
{
//play your animation
//make sure your animator isnt set to play on launch.
}