Beispiel #1
0
    // Call functions below after get the instance: MenuManager.GetInstance().functionName() or from other functions of this class.

    public void PlaySound(SoundNamesEnum sn, bool loop = false, int channel = -1)
    {
        AudioClip clip = audioClips[(int)sn];

        if (channel == -1)
        {
            bool played = false;

            for (int x = 0; x < soundSources.Length; x++)
            {
                if (!soundSources [x].isPlaying)
                {
                    soundSources [x].clip = clip;
                    soundSources [x].loop = loop;
                    soundSources [x].Play();
                    played = true;
                    break;
                }
            }

            if (!played)
            {
                soundSources [0].clip = clip;
                soundSources [0].loop = loop;
                soundSources [0].Play();
            }
        }
        else
        {
            soundSources [channel].clip = clip;
            soundSources [channel].loop = loop;
            soundSources [channel].Play();
        }
    }
Beispiel #2
0
    public float GetClipLength(SoundNamesEnum sn)
    {
        AudioClip clip = audioClips[(int)sn];

        return(clip.length);
    }