using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.SceneManagement; public class TutorialAudioManager : MonoBehaviour { public static TutorialAudioManager Instance; public Sound[] musicSounds; //Array which stores all music sounds public AudioSource musicSource; //Audio source to play music private void Update() { //if the current scene is not tutorial delete the AudioManager if (SceneManager.GetActiveScene().name != "Tutorial") { Destroy(gameObject); } //if instance is null, dont destory it else if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); } } private void Start() { PlayTutorialMusic("Tutorial Theme"); //playing tutorial theme when the game starts } public void PlayTutorialMusic(string name) { // Find the sound in the musicSounds array with the given name Sound s = Array.Find(musicSounds, X => X.name == name); if (s == null) { Debug.Log("Sound Not Found"); // Log an error if the sound is not found } else { musicSource.clip = s.clip; // Assign the found sound's clip to the music source musicSource.Play(); // Play the assigned music clip } } }