Play sound once when variable is less than 0

So I have barricades that can be broken. When they are, I want them to play a sound ONCE. The problem is that the sounds is being looped instead of being played once. This is because the code states:

if (barricadeHealth <= 0){
playsound;
}

How do I play the sound once every time a barricade goes below 0 hp?

u can look at c# events… you define a event like “onBarricadeDestroy”, and subscribe to those events… so you can execute some logic once they occur…

Hi,

What you’re looking for is the PlayOneShot() function :slight_smile: Here you go: Unity - Scripting API: AudioSource.PlayOneShot

And make sure that there is no loop property or so checked in the inspector of your audio file !