[3D跑酷] AudioManager

游戏中的声音管理最常用的组件莫过于AudioSource和AudioClip,我的做法是建立是一个AudioManager类(单例类)管理各个音频,谈一下我的经验:

imageimageimage

Start()函数:设置音频整体参数;

Inspector面板:拖拽文件赋值

查看相关API

 

主要逻辑:

 public void playSoundEffect(SoundEffects soundEffect)

    {

        AudioClip clip = null;

        float pitch = 1;

        switch (soundEffect) {

            case SoundEffects.ObstacleCollisionSoundEffect:

                clip = obstacleCollision;

                break;

            case SoundEffects.CoinSoundEffect:

                clip = coinCollection;

                pitch = 1.5f;

                break;

            case SoundEffects.PowerUpSoundEffect:

                clip = powerUpCollection;

                break;

            case SoundEffects.GameOverSoundEffect:

                clip = gameOver;

                break;

            case SoundEffects.GUITapSoundEffect:

                clip = guiTap;

                break;

        }

        soundEffectsAudio.pitch = pitch;//音调

        soundEffectsAudio.clip = clip;//

        soundEffectsAudio.Play();

    }

你可能感兴趣的:(manager)