示例#1
0
    public void PlaySFX(KeySFX key, bool playOnLoop = false)
    {
        AudioClip newClip = null;

        switch (key)
        {
        case KeySFX.Enable:
            newClip = enableSFX;
            break;

        case KeySFX.Ambiance:
            newClip = ambianceSFX;
            break;

        case KeySFX.Disable:
            newClip = disableSFX;
            break;

        case KeySFX.Death:
            newClip = deathSFX;
            break;
        }

        if (newClip != null && (playOnLoop == false || audioSource.isPlaying == false))
        {
            audioSource.clip = newClip;
            audioSource.loop = playOnLoop;
            audioSource.Play();
        }
    }
    public void PlaySFX(KeySFX key)
    {
        AudioClip newClip    = null;
        bool      playOnLoop = false;

        switch (key)
        {
        case KeySFX.Walk:
            newClip    = walkSFX;
            playOnLoop = true;
            break;

        case KeySFX.Dash:
            newClip = dashSFX;
            break;

        case KeySFX.Death:
            newClip = deathSFX;
            break;
        }

        if (newClip != null && (playOnLoop == false || audioSource.isPlaying == false))
        {
            audioSource.clip = newClip;
            audioSource.loop = playOnLoop;
            audioSource.Play();
        }
    }