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.

in Projects by (217 points)

I thought something like that in general:

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

pass 

1 Answer

+3 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.

by (3,991 points)
selected by

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories