using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TurnOnOffSound : MonoBehaviour { AudioSource audioData; public AudioClip AlarmRing; bool bSound=false; public bool bTurnOn=false; public Sprite[] spSwitch; public Button btnSwitch; // Use this for initialization void Start () { audioData = this.gameObject.GetComponent(); audioData.clip = AlarmRing; } // Update is called once per frame void Update () { if ((bTurnOn == true) && (bSound == false)) { audioData.Play(); bSound = true; } if ((bTurnOn == false) && (bSound == true)) { audioData.Stop(); bSound = false; } } public void TurnOn() { if (bTurnOn == true) { bTurnOn = false; btnSwitch.image.sprite = spSwitch [0]; } else { bTurnOn = true; btnSwitch.image.sprite = spSwitch [1]; } } }