How to Play Music Between Scenes in Unity
You want to make a game, but whenever you load a new scene, the background music reverts to the beginning? Don't worry! This tutorial will explain how to fix this problem in the right way. When you import your own audio asset (anywhere on your computer), you will always hear it if you add an audio source object in Unity. But when you navigate to a new scene, the music playback will stop if the scene doesn't have an audio source or it will play the audio from the beginning if there is an audio source already available. What should you do in order to fix it?
First of all, you need to assign a scene loading script that will be used for both buttons in your project. The buttons will be powered with the so-called OnClick() functions, but the scenes need to be present in the Scene Manager, located in the Build Settings.
For moving to another scene, make a simple script that will be part of the audio object. That script, on the other hand, will contain the information which is needed in order to play music between scenes. The method DontDestroyOnLoad is used every time you have an object that should remain in both scenes.
There is also an optional part that includes adding a toggle for controlling if the sound is on or off. The part isn't very well explained, it is just used for testing purposes.
Support the Creator of Kozmobot on the social networks!
CHECK OUT MY WEBSITE: http://kozmobot.com
INSTAGRAM: https://www.instagram.com/kozmobot.channel
TIKTOK: https://www.tiktok.com/@kozmobot.channel
MUSIC IN THE VIDEO: https://www.youtube.com/watch?v=G87ovAyzLEs
Видео How to Play Music Between Scenes in Unity канала Kozmobot Games
First of all, you need to assign a scene loading script that will be used for both buttons in your project. The buttons will be powered with the so-called OnClick() functions, but the scenes need to be present in the Scene Manager, located in the Build Settings.
For moving to another scene, make a simple script that will be part of the audio object. That script, on the other hand, will contain the information which is needed in order to play music between scenes. The method DontDestroyOnLoad is used every time you have an object that should remain in both scenes.
There is also an optional part that includes adding a toggle for controlling if the sound is on or off. The part isn't very well explained, it is just used for testing purposes.
Support the Creator of Kozmobot on the social networks!
CHECK OUT MY WEBSITE: http://kozmobot.com
INSTAGRAM: https://www.instagram.com/kozmobot.channel
TIKTOK: https://www.tiktok.com/@kozmobot.channel
MUSIC IN THE VIDEO: https://www.youtube.com/watch?v=G87ovAyzLEs
Видео How to Play Music Between Scenes in Unity канала Kozmobot Games
nav mesh unity tutorial unity unity tutorials game development tutorials 3d platformer music unity 3d platformer tutorial 3d platformer in unity music between scenes unity unity game tutorial music between scenes unity music between scenes background music in unity music in unity music between scenes unity tutorial unity music between audio source unity audio source in unity tutorial audio unity tutorial
Комментарии отсутствуют
Информация о видео
18 января 2024 г. 18:40:23
00:06:16
Другие видео канала