I have a simple script that should cycle through 4 music tracks and select the next one to be played.
nextSong = Random.Range(0, 3);
I've run my game approx 50 times and its never been 3. It's been 0 and 2 mostly but occasionally 1.
Is this something to do with it being rounded/casted from float to int?
nextSong is declared as an Int.
Anyone know whats going on here? Surely it cannot miss track 3 more than 50 times, or was it just many consecutive "lucky" rolls for 0 and 2?
Here is all the code in case it is relevant:
void Update () {
if (!audioSource.isPlaying)
{
nextSong = Random.Range(0, 3);
audioSource.clip = songs[nextSong];
audioSource.Play();
Debug.Log("should be playing next random track number : " + nextSong + "called: " + songs[nextSong]);
}
}