How do I animate my enemy randomly with time?

Hi there! I am currently struggling to animate my enemy character for a class project. Most of the answers I find about animation scripting are about the player character that animates with inputs or about enemies entering a collision area and then following the player triggering animations on certain cues.

What I am trying to do however is simply play my enemy’s animations at random over time. The basic idea is like a whack a mole game that will throw rigid body projectiles at you.

My enemy’s possible states are…

1.) Underground (“emerge” animation sitting at frame 1, no animation)

2.) Emerging (plays “emerge” animation)

3.) Idling (plays “idle” animation)

4.) Attacking (plays “attack” animation)

5.) Retreating (plays “emerge” animation in reverse, possible through rewind function / ping pong wrap?)

So in play, I’d like to, at random, have the enemy emerge, idle 1-3 times, attack after idle finishes, maybe idle again, possibly attack again after the idle, then retreat back underground.

Also about 2 seconds after his attack starts he’ll spawn a prefab rigidbody that flies towards my characters last known location.

All I’m looking for right now though is how to get the guy to animate without user input or any cues from the player at all. Simply randomly do his motions.

I do not know if this is simple or complex, any help is appreciated, I am coding-impaired.

You Could do Something like this …

selectJumpAnim = Random.Range(0,2);
			if(selectJumpAnim == 0){
				myAnim.Play("jump");
			}
			else if(selectJumpAnim == 1){
				myAnim.Play("jumpRol");
			}

For doing somethign after some seconds you could use

Invoke("method_name",2.0f);