This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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 Engine by (223 points)

I thought something like that in general:

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

pass 

1 Answer

+4 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 (4,246 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 Frequently asked questions and 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 [email protected] with your username.