[3D跑酷] AudioManager

前端之家收集整理的这篇文章主要介绍了[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();
    }
原文链接:/unity/995668.html

猜你在找的Unity相关文章