Topic was automatically imported from the old Question2Answer platform.
Asked By
Juan
I have this code, where I have embedded the sound to play when the button is pressed which also connected to the scene transition. Therefore, the order of my transition would be Enter button pressed, and then the sound played, and then the transition.
func _input(event):
if event.is_action_pressed(“NextLevelEat”):
$NextLevelSound.play()
if get_overlapping_bodies().size() > 0:
visible = false
change_to_next_level()
This is the code I have, but when the scene is played the sound is very short instead of the length of the audio it should be.
The scene changes before the sound has finished playing. Try making the script wait until the sound finishes playing. (Note: I don’t know if this is how the code is structured.)
func input(event):
if event.is_action_pressed("NextLevelEat"):
$NextLevelSound.play()
# Stop the script until the sound has completed playing.
yield($NextLevelSound, "finished")
if get_overlapping_bodies().size() > 0:
visible = false
change_to_next_level()
Please note that the “finished” signal won’t be emitted if the sound loops.