Topic was automatically imported from the old Question2Answer platform.
Asked By
20xxdd20
I have a simple script:
if Input.is_action_just_pressed("left_mouse_button"):
$ShootSound.play()
The only problem is, the sound sometimes doesn’t play. Seems like it didn’t load and after spamming LMB, the sound is working but if you don’t use it for sometime, it doesn’t play anymore until you try to use it again a few times.
The reason for this could be that the sound is already playing. If left click/“fire” button is pressed repeatedly, the sound will be played from the beginning each time. What may have to be checked is whether the sound is playing:
if Input.is_action_just_pressed("left_mouse_button"):
if not $ShootSound.is_playing():
$ShootSound.play()
It may also be a good idea to put in a small “cool down” for the weapon, e.g. 0.2 or 0.3 seconds.