I am making a 2D game. When the player’s health drops to 0 (when the player dies), I want a sound effect to play. How can I do it? Any kind of help would be appreciated. Thanks ![]()
Attach an Audio Source component, and basically, in psuedocode:
AudioSource youraudiosource;
void Update () {
if (healthscript.currentHealth <= 0)
youraudiosource.Play();
}
Okay I fixed it. I used GetComponent to access the audio source, and then I used .play in the if statemnt and .Stop in void Start. Thanks for your help ![]()