Hello everyone, I want to play the music between MainMenu and Upgrade scenes. When i open other scene, i want to destroy the music. The following codes did not work. Could you help me, please?
Awake runs once for every object, so that wont be called when a new scene is loaded. You’re looking for sceneLoaded, which you can use to add a delegate for when a new scene is loaded.
So you code would look something like this:
void Awake()
{
DontDestroyOnLoad (music);
// add the callback method when scene loads
SceneManagement.sceneLoaded += OnSceneLoad;
}
// called when scene loads
void OnSceneLoad(Scene scene, LoadSceneMode mode)
{
if(scene.buildIndex != indexOfMenuScene || scene.buildIndex != indexOfUpgradeScene)
{
Destroy(music);
}
}
@UnityEdwardPogii Uhhh… are you asking where that code is supposed to go? If so I HIGHLY recommend you watch the Unity scripting tutorials before diving any further into coding.
In any case, that code goes inside a C# class that you create in the editor, which goes on a singleton object created when the game starts.
Hi people,
I have an audio button in my game for audio on/off. When I am playing the game and if turned the audio off and return to main menu to play new game. When I start the game my audio is still off. I want a solution where if i return to main menu scene the audio object must destroy/reset in some way that when I start the game again the music start playing.
Thanks.