Does Anyone know how to Change Music from the Start Scene to Next Level?

I am having a difficult time with coding where I can change the music(using animation to fade in and fade out the music).
My code is this currently

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour
{
public Animator musicAnimation;
public float waitTime;

public void LoadNextScene()
{
    
    int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    SceneManager.LoadScene(currentSceneIndex + 1);
  
        
}

public void LoadStart()
{
    SceneManager.LoadScene(0);
    FindObjectOfType<GameStatus>().ResetGame();
}
public void QuitGame()
{
    Application.Quit();
}
IEnumerator ChangeScene()
{
    musicAnimation.SetTrigger("FadeOut");
    yield return new WaitForSeconds(waitTime);
    LoadNextScene();
    Debug.Log("RUREADY");
  
   
}
public void StartButtonMusic()
{
    
  StartCoroutine(ChangeScene());
}

}
/////
I know it is not even passing into ChangeScene from my debug.Log and it tells me for the StartCoroutine(ChangeScene()) that Scene Loader is inactive, but how would I even activate it? And how can it be inactive if I can change scenes just fine?

Hi Novice164,

Please look up the sceneLoaded delegate in the API. I think that’s what you might need to change and play music when a new scene was loaded.

Did this help?


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms