- Edited
I have a stamina bar in my game, and when the value is equal to 0, I want an AudioStreamPlayer3D
to play a specific sound. Here's the code I used:
onready var PlayerAudio = $"../../../../../../PlayerAudio"
const tired_sight = preload("res://SFX/Player/Tired sighs.wav")
func _physics_process(delta):
if value == 0:
PlayerAudio.stop()
if PlayerAudio.is_playing() == false:
PlayerAudio.stream = tired_sight
PlayerAudio.play()
What it does is: first check if the value of the stamina is zero, if it is, then stop the Audio that the AudioStreamPlayer
is playing (this is supposed to stop a “running” sound effect, which I want to stop when running out of stamina). Stopping this audio is important because there's always another sound playing the moment before the value gets to zero. After that, it checks if the node is playing something, but since the audio is stopped before, the condition is always false (no audio playing). Finally, if there isn't any audio playing, then play the “tired” sound effect.
The issue is that for some reason, the AudioStreamPlayer
stops, but the sound starts playing when the stamina is no longer zero (stamina recharges after a few seconds). The "tired" sound should play when the stamina is zero.