I want music in my game to start when the player enters areas and stop when leaving. After leaving, new music would start. How would I do this?
1 Answer
1If you are thinking of swapping background music, you can do either of these 2:
Audio Source Area
Dead simple, just setup a super large audioSource area, with the audio-clip set as 2D-sound. Place multiple audioSource strategically to get the effect of changing bgm in different area.
Pros
- Easy to setup
- If setup correctly, you will get a nice cross-fade between the bgm
Cons
- Cannot handle overlap area (for example, a forest has 1 bgm, a house has 1 bgm, a house in a forest will use both, you can’t make it use just the house bgm)
Audio Trigger
Put a audio-source in your player, set it as 2D sound. Change the audio clip of the audio-source whenever you enter a specific area.
Pros
- More control over the audio
- Will not produce overlap area
Cons
- Slightly difficult to setup