using System.Collections; using System.Collections.Generic; using UnityEngine; /* -------------------------------------- Project: Programing assessment Standard: 91906 (AS3.7) v.1 School: Tauranga Boys' College Author: Rauputu Noah Phizacklea Date: August 2024 Unity: 2021.3.18f --------------------------------------- */ public class AudioManager : MonoBehaviour { [Header("-------------- Audio Source --------------")] [SerializeField] AudioSource musicSource; // Source for playing background music [SerializeField] AudioSource SFXSource; // Source for playing sound effects (SFX) [Header("-------------- Audio Clips --------------")] public AudioClip bgMusic; // Background music clip public AudioClip playerDeathSFX; // SFX for player death public AudioClip checkpointSFX; // SFX for reaching a checkpoint public AudioClip swordAttackSFX; // SFX for sword attack public AudioClip bulletAttackSFX; // SFX for bullet attack public AudioClip slimeDeathSFX; // SFX for slime death public AudioClip rollSFX; // SFX for player rolling public AudioClip healPickupSFX; //SFX for player healing from health pickup public AudioClip healPotionSFX; //SFX for player healing from health potion public AudioClip coinSFX; //SFX for coin pickup public static AudioManager instance; // Singleton instance of AudioManager private void Awake() { // Ensure only one instance of AudioManager exists if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); // Persist this object across scene loads } else { Destroy(gameObject); // Destroy duplicate AudioManager instances } } private void Start() { // Set the background music clip and start playing it musicSource.clip = bgMusic; musicSource.Play(); } public void PlaySFX(AudioClip clip) { // Play the provided sound effect clip once SFXSource.PlayOneShot(clip); } }