|
|
|
| View previous topic :: View next topic |
BogdanDude

Joined: 18 Jun 2009 Posts: 38
|
Posted: Thu Sep 17, 2009 11:59 am Post subject: How to best implement Sfx ON/OFF toggles in the pause menu |
|
|
|
Hello!
I'm trying to implement the option to turn the SFX on or off, and also the music on or off from an ingame pause menu.
So far I checked on every gameobject that had an Audiosource on them if a variable on another game object is true or false. So, if 'sfxOn' was true, it would play the sound.
The problem is that when the SFX button is turned on or off in the pause options menu, I'm not sure how to update that variable on every gameobject. The hard way could be to call a Broadcast message on a parent of all gameobject and tell them to switch their own sfxOn bool variable.
I guess a much easier way could be to use a static variable for sfxOn. Could you please write me a simple line of code how to access a static variable from another gameobject and keep a reference to it (if possible, in the Awake method).
If you have some easier methods to implement switching sound on and off (and still keep the music and sound effects as separate options), please let me know.
Thanks a lot,
Bogdan |
|
| Back to top |
|
|
Eric5h5
Joined: 19 Jul 2006 Posts: 8107
|
Posted: Thu Sep 17, 2009 7:40 pm Post subject: Re: How to best implement Sfx ON/OFF toggles in the pause me |
|
|
|
I made a function for playing sounds and also one for music, so I call those when playing audio. The functions use the normal Unity sound routines, but also have a bit of code to check to see if sounds/music should be played or not. If not, they don't do anything:
| Code: | function PlayMusic (musicClip : AudioClip, doesLoop : boolean) {
if (useMusic) {
audio.clip = musicClip;
audio.loop = doesLoop? true : false;
audio.Play();
}
} |
--Eric |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|
|
|
|