Play animation randomly from an array js

Hello All,

I was wondering if someone could shed some light on how to randomly play animations without pressing a gui button.Each animation should play fully before next random selection begins. i looked up and down for some solution to this,i came across random.range, but im not sure how to make it play each animation to the end. i’ll keep looking but any help will be appreciated.

Thankyou for your response.

PlayQueued(anims[Random.Range(0, anims.length)])

i came across this and it seemd to work just fine.

Create a script that will contain the array of animations, and a function called pickRandomAnimation.
Then u can call this function on the end of each animation Animation Events

The function will use Random.Range to get an index of the array, and then u will use this index to pick and animation and play Animation.Play .

I don’t have Unity here, so i can’t write some code for you, but if you dont understand how to do something just ask in the comments :slight_smile:

This isn’t the only solution, i can think of at least another one, but this one is easier.