I have a title scene and a credits scene that use the same music. When I start my game the title scene music plays, and I have my game set up so the audio manager is not destroyed on load. When I enter my credits scene I do not instruct any new music to play, but each time I reload my title scene the title music restarts because a script in the scene tells it do so.
How can I get the name of the current audio track so that I will only play audio if it differs from what's currently being played?
This is my "LevelMaster" script which is responsible for handling the audio in each scene.
public class LevelMaster : MonoBehaviour
{
private AudioManager AudioManager;
[SerializeField]
private string trackName;
private void Start()
{
AudioManager = GameObject.Find("AudioManager").GetComponent<AudioManager>();
AudioManager.Play(trackName);
}
public void PlaySound(string soundName)
{
AudioManager.Play(soundName);
}
public void StopSound(string soundName)
{
AudioManager.Stop(soundName);
}