示例#1
0
    private void Start()
    {
        hasVoice = PlayerPrefUtil.isVoice();

        if (!hasVoice)
        {
            audioSource.Stop(); //停止播放音乐
        }
        else
        {
            audioSource.Play(); //播放音乐
        }
    }
示例#2
0
 /// <summary>
 /// 改变声音选项
 /// </summary>
 public void ChangeVoice()
 {
     AudioUtil.sInstance.hasVoice = !PlayerPrefUtil.isVoice();
     PlayerPrefUtil.setVoice(AudioUtil.sInstance.hasVoice); //设置一下声音变量
     if (AudioUtil.sInstance.hasVoice)
     {
         AudioUtil.sInstance.PlayBGM();                     //播放背景音乐
         transform.GetChild(0).gameObject.SetActive(false); //有声音
     }
     else
     {
         AudioUtil.sInstance.StopPlayBGM();                //停止背景音乐
         transform.GetChild(0).gameObject.SetActive(true); //静音
     }
 }