SoundButtonHandler.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using UnityEngine;
  2. using System.Collections;
  3. public class SoundButtonHandler : MonoBehaviour {
  4. enum State { On, Off }
  5. private SoundManagerCS hSoundManagerCS;
  6. private UIToggle uicSound;
  7. private State state;//if the music is ON of OFF
  8. public UIButtonScale buttonTarget;
  9. void Start ()
  10. {
  11. buttonTarget = GetComponent<UIButtonScale>();
  12. hSoundManagerCS = (SoundManagerCS)GameObject.Find("SoundManager").GetComponent(typeof(SoundManagerCS));
  13. uicSound = (UIToggle)this.GetComponent(typeof(UIToggle));
  14. //check if the script is a part of On or Off radio button
  15. if (this.name == "On")
  16. state = State.On;
  17. else
  18. state = State.Off;
  19. //set the Music radio button to On or Off
  20. if (state == State.On)
  21. {
  22. if (hSoundManagerCS.isSoundEnabled())
  23. uicSound.isChecked = true;
  24. else
  25. uicSound.isChecked = false;
  26. }
  27. else if (state == State.Off)
  28. {
  29. if (!hSoundManagerCS.isSoundEnabled())
  30. uicSound.isChecked = true;
  31. else
  32. uicSound.isChecked = false;
  33. }
  34. }//end of Start()
  35. void OnActivate(bool isTrue)
  36. {
  37. if (isTrue && state == State.On)
  38. {
  39. hSoundManagerCS.toggleSoundEnabled(true);
  40. buttonTarget.tweenTarget.GetComponent<UIWidget>().color = Color.grey;
  41. Debug.Log("Color On");
  42. }
  43. else if (isTrue && state == State.Off)
  44. {
  45. hSoundManagerCS.toggleSoundEnabled(false);
  46. buttonTarget.tweenTarget.GetComponent<UISprite>().color = Color.white;
  47. }
  48. }
  49. }