using System.Collections; using System.Collections.Generic; using UnityEngine; public class MusicManager : MonoBehaviour { public static MusicManager Instance { get; private set; } [SerializeField] AnimationCurve projectilesToIntensity; [SerializeField] AudioClip[] intensities; private int prevIntinsity = -1; private AudioSource[] sources; void Awake() { sources = new AudioSource[intensities.Length]; } private void Update() { int projectileCount = GameObject.FindObjectsByType(FindObjectsSortMode.None).Length; int intensity = (int) projectilesToIntensity.Evaluate(projectileCount) - 1; if (intensity > prevIntinsity) { sources[intensity] = AudioManager.PlaySound(intensities[intensity], Vector3.zero, false, false, true, true); } else if (intensity < prevIntinsity) { if (sources[prevIntinsity] != null) sources[prevIntinsity].Stop(); } prevIntinsity = intensity; } }