My game sets the timeScale to 0 in between waves so that the player can upgrade weapons and barriers in menus without the next wave starting. However, I also have background music playing that has an intro. I created a second audio clip that does not have an intro which i have set up to start once the timer reaches a certain time. The menu, and subsequently the timeScale freeze, are effecting the timer that tells the audio manager when to play the second clip. Is there a way to make this timer work independently of the timeScale?
public float timer;
public Sound[] sounds;
// Start is called before the first frame update
void Awake()
{
foreach (Sound s in sounds)
{
s.source = gameObject.AddComponent<AudioSource>();
s.source.clip = s.clip;
s.source.volume = s.volume;
s.source.pitch = s.pitch;
s.source.loop = s.loop;
}
}
void Start()
{
Play("Theme");
timer = 0f;
}
public void Update()
{
timer += Time.deltaTime;
if (timer >= 240f)
{
Play("Theme 2");
}
}
public void Play (string name)
{
Sound s = Array.Find(sounds, sound => sound.name == name);
if (s == null)
{
Debug.LogWarning("Sound" + name + "not found!");
return;
}
s.source.Play();
}
This is the code for reference.