0 votes

When i start my game, at the same time starts and the music.I have created a button that if someone press it ,i want the music stop and if press it again i want the music starts. If i send a signal from button to AudioStreamPlayer node ιs there a specific code to stop and play the music again?

I thought something like that in general:

#

func onButtonpressed():
get
tree().<= not get_tree().

pass 

#

Thank you.

asked Jun 5, 2019 in Projects by Nick888 (216 points)

I thought something like that in general:

func onButtonpressed():
get
tree().playmusic= not get_tree().playmusic

pass 

1 Answer

+2 votes
Best answer

This will toggle the first audio bus:

AudioServer.set_bus_mute(0, not AudioServer.is_bus_mute(0))

You might wanna create a separate audio bus for sound effects, for example.
More info on Audio Buses.

answered Jun 5, 2019 by Dlean Jeans (3,873 points)
selected Jun 5, 2019 by Nick888

Thank you very very much!!!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.