Unity音频管理
游戏中的声音管理最常用的组件莫过于AudioSource和AudioClip,我的做法是建立是一个AudioManager类(单例类)管理各个音频,谈一下我的经验:
函数列表
Start函数:设置音频整体参数;
编辑器面板
拖拽文件赋值
AudioSource文档
逻辑实现代码
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(); }