Hello
How can i play randomly music clips? i have about 43 clips and want them to be played randomly in the game. how can i do this?
Hello
How can i play randomly music clips? i have about 43 clips and want them to be played randomly in the game. how can i do this?
In code make an array for your 43 clips, then drag and drop the audio clips into each slot. Use the Random.Range function to compute a number between 0 and 42, then set that clip to your AudioSource.
I would take a look at arrays, Random.Range, and indexing.
For instance, your variable for an array for all of your clips would look like:
var myClips : AudioClip[] = new AudioClip[43];
So that makes an array of all of your audio clips. Dragging and dropping them might be tedious though -_-
Now you can use Random.Range. You want your min to be 0 because indexing starts at 0 and your max can be 43 because in Random.Range the max value is exclusive.
Now you can just use indexing to get:
var chosenClip : AudioClip = myClips[ Random.Range( 0,43 )];
And you can do that as much as you want!
Hope this helps. If there is anything I was unclear about just let me know!
If one of these answers was acceptable to you, will you please mark your question as answered and one of the provided answers as the answer for future users that might stumble upon this? The button is the checkmark. Thanks!
– youngapprentice_1