Exemplo n.º 1
0
    void Start()
    {
        //好用的東東但用不到 會取所有的AudioSource 連帶影響到BGM
        //SFXSource = FindObjectsOfType(typeof(AudioSource))as AudioSource[];
        //抓取全部有以下 Tag的物件
        SFXGameObjectGroup1 = GameObject.FindGameObjectsWithTag("Monster");
        SFXGameObjectGroup2 = GameObject.FindGameObjectsWithTag("SFXSource");//本來只有一個現在Player跟Canvas
        getHitEffect        = FindObjectOfType <GetHitEffect>();
        BGMSource           = GetComponent <AudioSource>();
        //音量初始
        //foreach (AudioSource SFXAudioSource in SFXSource)
        //{
        //    SFXAudioSource.volume = CentralData.GetInst().SFXVol;
        //}
        //所有有Monster Tag的物件的音量全部設定
        foreach (GameObject SFXAudioSource in SFXGameObjectGroup1)
        {
            SFXAudioSource.GetComponent <AudioSource>().volume = CentralData.GetInst().SFXVol;
        }
        foreach (GameObject SFXAudioSource in SFXGameObjectGroup2)
        {
            SFXAudioSource.GetComponent <AudioSource>().volume = CentralData.GetInst().SFXVol;
        }

        BGMSource.volume = CentralData.GetInst().BGMVol;
        BGMSlider.value  = CentralData.GetInst().BGMVol;
        SFXSlider.value  = CentralData.GetInst().SFXVol;
    }
Exemplo n.º 2
0
    public void SetSFXVol(float v)
    {
        //CentralData.GetInst().SFXVol = v;
        //foreach (AudioSource audioSource in SFXSource)
        //{
        //    audioSource.volume = v;
        //}

        foreach (GameObject SFXAudioSource in SFXGameObjectGroup1)
        {
            SFXAudioSource.GetComponent <AudioSource>().volume = v;
        }
        foreach (GameObject SFXAudioSource in SFXGameObjectGroup2)
        {
            SFXAudioSource.GetComponent <AudioSource>().volume = v;
        }
    }