1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using UnityEngine;
- using System.Collections;
- public class SoundButtonHandler : MonoBehaviour {
-
- enum State { On, Off }
-
- private SoundManagerCS hSoundManagerCS;
- private UIToggle uicSound;
- private State state;//if the music is ON of OFF
- public UIButtonScale buttonTarget;
-
- void Start ()
- {
- buttonTarget = GetComponent<UIButtonScale>();
- hSoundManagerCS = (SoundManagerCS)GameObject.Find("SoundManager").GetComponent(typeof(SoundManagerCS));
- uicSound = (UIToggle)this.GetComponent(typeof(UIToggle));
-
- //check if the script is a part of On or Off radio button
- if (this.name == "On")
- state = State.On;
- else
- state = State.Off;
-
- //set the Music radio button to On or Off
- if (state == State.On)
- {
- if (hSoundManagerCS.isSoundEnabled())
- uicSound.isChecked = true;
- else
- uicSound.isChecked = false;
- }
- else if (state == State.Off)
- {
- if (!hSoundManagerCS.isSoundEnabled())
- uicSound.isChecked = true;
- else
- uicSound.isChecked = false;
- }
- }//end of Start()
-
- void OnActivate(bool isTrue)
- {
- if (isTrue && state == State.On)
- {
- hSoundManagerCS.toggleSoundEnabled(true);
- buttonTarget.tweenTarget.GetComponent<UIWidget>().color = Color.grey;
- Debug.Log("Color On");
- }
-
- else if (isTrue && state == State.Off)
- {
- hSoundManagerCS.toggleSoundEnabled(false);
- buttonTarget.tweenTarget.GetComponent<UISprite>().color = Color.white;
- }
-
- }
-
- }
|