0
Answered

random music playback

Stanislav 4 months ago in Game Creator updated by Marti (Lead Developer) 4 months ago 9


How can I create random music playback? For example, I want to use 5 tracks in a scene, and how is it possible with GC?

Unity version:
Unity 2018.4.22f1 (64-bit)
Game Creator version:
1.1.6
+1

Yes I just noticed that list variables do not have an audio / sound variable. That would make things very easy.

You would have to use conditions, random number and actions to play that sound from the random number.

But if we could put them into a list you would just pick a random item from the list and play it.

with the action random variable and select your list.

So Marti please put sounds into list variables. 

+1

Yes, that would be great. Or in the actions of music one could insert several tracks. And play them either randomly or on a list.

So will Marty do it or not? Or can it be somehow solved?

There is a way to do this just with trigger on enable.

1. create a trigger and set it to OnEnable

2. add an action play music and add your first song.

3. Disable this trigger game object.

4. make as many of these you need for different songs.

5. make a trigger and action that will set active on one of the above deactivated objects and it will play.

6. you just have to use random variables and put those disabled triggers into a list.

7. and then call with a random gameobject from list to play one.


I will make a video later on tonight.

Thank you for the video! I use this method a little differently. I do not change music at the moment when the player enters the collider. I need the music to change when one track ends. I just write the wait command along the length of the track. Then I set the variable and then the trigger works by changing the variable. There is a minus. I use the pause in the game and set the time scale to 0.


Not enough ticks, wait for the music to end.

Answered

If you need to play some music when one track finishes, I think it's best to attach the music clip at the end of the track using an audio editing program. Music is supposed to loop, so the timer trick could not work 100% due to floating point precision.