[3D跑酷] AudioManager

Unity音频管理

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

函数列表

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

image

编辑器面板

拖拽文件赋值

image

AudioSource文档

image

 

逻辑实现代码

 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();
    }
posted @ 2013-10-31 10:55  赵青青  阅读(888)  评论(2编辑  收藏  举报