MusicButtonHandler.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. using System.Collections;
  3. public class MusicButtonHandler : MonoBehaviour {
  4. enum State { On, Off }
  5. private SoundManagerCS hSoundManagerCS;
  6. private UIToggle uicMusic;
  7. private State state;//if the music is ON of OFF
  8. void Start ()
  9. {
  10. hSoundManagerCS = (SoundManagerCS)GameObject.Find("SoundManager").GetComponent(typeof(SoundManagerCS));
  11. uicMusic = (UIToggle)this.GetComponent(typeof(UIToggle));
  12. //check if the script is a part of On or Off radio button
  13. if (this.name == "On")
  14. state = State.On;
  15. else
  16. state = State.Off;
  17. //set the Music radio button to On or Off
  18. if (state == State.On)
  19. {
  20. if (hSoundManagerCS.isMusicEnabled())
  21. uicMusic.isChecked = true;
  22. else
  23. uicMusic.isChecked = false;
  24. }
  25. else if (state == State.Off)
  26. {
  27. if (!hSoundManagerCS.isMusicEnabled())
  28. uicMusic.isChecked = true;
  29. else
  30. uicMusic.isChecked = false;
  31. }
  32. }//end of Start()
  33. void OnActivate(bool isTrue)
  34. {
  35. if (isTrue && state == State.On)
  36. hSoundManagerCS.toggleMusicEnabled(true);
  37. else if (isTrue && state == State.Off)
  38. hSoundManagerCS.toggleMusicEnabled(false);
  39. }
  40. }