In my 2D game, I have this audio which goes on forever with DontDestroyOnLoad. When the character’s health drops to 0, I want to stop that audio. How can I do it? Any help would be appreciated. Thanks ![]()
AudioSource youraudiosource;
void Update () {
if (healthscript.currentHealth <= 0)
youraudiosource.Stop();
}
to append:
you seem to be working with multiple audio sources on one object, i recommend using an array to deal with that
ie
public AudioSource[] youraudiosources;
//then put those sources in the inspector, dragging and dropping the components
void Update () {
if (healthscript.currentHealth <= 0)
//play death sound
youraudiosources[0].Play();
//stop life sound
youraudiosources[1].Stop();
}