SoundToggle
How do I use Sound Toggle
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
17 | soundToggle.isOn = true; | 1 |
53 | public void SoundToggle(){ | 2 |
File name: MainMenuController.cs
Copy
13 void Start () {
14 if(GameController.instance != null && MusicController.instance != null){
15 if (GameController.instance.isMusicOn) {
16 MusicController.instance.PlayBgMusic ();
17 soundToggle.isOn = true;
18 } else {
19 MusicController.instance.StopAllSounds ();
20 soundToggle.isOn = false;
21 }
22 }
23 }
File name: MainMenuController.cs
Copy
53 public void SoundToggle(){
54 if (soundToggle.isOn) {
55 GameController.instance.isMusicOn = true;
56 MusicController.instance.PlayBgMusic ();
57 GameController.instance.Save ();
58 } else {
59 GameController.instance.isMusicOn = false;
60 MusicController.instance.StopAllSounds ();
61 GameController.instance.Save ();
62 }
63 }
SoundToggle 143 lượt xem
Gõ tìm kiếm nhanh...