/// <summary> /// Play random player sound. /// </summary> /// <param name="playerSoundType">PlayerSoundType to play.</param> public void PlayRandomSound(PlayerSoundType playerSoundType) { switch (playerSoundType) { case PlayerSoundType.Hurt: audioSource.clip = playerHurtClips.GetRandomElementOrDefault(); break; case PlayerSoundType.Idle: audioSource.clip = playerIdleClips.GetRandomElementOrDefault(); break; case PlayerSoundType.Jump: audioSource.clip = playerJumpClips.GetRandomElementOrDefault(); break; case PlayerSoundType.Land: audioSource.clip = playerLandClips.GetRandomElementOrDefault(); break; case PlayerSoundType.Footstep: audioSource.clip = playerFootstepClips.GetRandomElementOrDefault(); break; } audioSource.Play(); }
/// <summary> /// 播放对应的音效 /// </summary> /// <param name="name"></param> public void Play(PlayerSoundType name) { switch (name) { case PlayerSoundType.run: AudioSources[0].Play(); break; case PlayerSoundType.jump: AudioSources[1].Play(); break; case PlayerSoundType.falldown: AudioSources[2].Play(); break; case PlayerSoundType.throwcube: AudioSources[3].Play(); break; case PlayerSoundType.flash: AudioSources[4].Play(); break; case PlayerSoundType.hook: AudioSources[5].Play(); break; case PlayerSoundType.stoptime: AudioSources[6].Play(); break; case PlayerSoundType.hit: AudioSources[7].Play(); break; case PlayerSoundType.trampoline: AudioSources[8].Play(); break; case PlayerSoundType.dead: AudioSources[9].Play(); break; default: break; } }
public void CreateSound(PlayerSoundType type, int playerNum, Vector3 position, float minVolume, float maxVolume) { PlayerSoundList playerSoundList = this.playerSounds[(int)type]; if (playerSoundList.clipLists == null || playerSoundList.clipLists.Length == 0) { Debug.LogWarning("No clips for " + type); return; } // Get list of sounds for this playerNum if (playerNum > playerSoundList.clipLists.Length) { Debug.LogWarning("playerNum " + playerNum + " is too high"); playerNum %= playerSoundList.clipLists.Length; } AudioClipList clipList = playerSoundList.clipLists[playerNum]; AudioClip clip = clipList.items[UnityEngine.Random.Range(0, clipList.items.Length)]; CreateSound(position, clip, minVolume, maxVolume); }
public void CreateSound(PlayerSoundType type, int playerNum, Vector3 position, float minVolume, float maxVolume) { PlayerSoundList playerSoundList = this.playerSounds[(int)type]; if (playerSoundList.clipLists == null || playerSoundList.clipLists.Length == 0) { Debug.LogWarning("No clips for " + type); return; } // Get list of sounds for this playerNum if(playerNum > playerSoundList.clipLists.Length) { Debug.LogWarning("playerNum " + playerNum + " is too high"); playerNum %= playerSoundList.clipLists.Length; } AudioClipList clipList = playerSoundList.clipLists[playerNum]; AudioClip clip = clipList.items[UnityEngine.Random.Range(0, clipList.items.Length)]; CreateSound(position, clip, minVolume, maxVolume); }
/// <summary> /// 检测该音效是否正在播放 /// </summary> /// <param name="name"></param> /// <returns></returns> public bool IsPlaying(PlayerSoundType name) { switch (name) { case PlayerSoundType.run: return(AudioSources[0].isPlaying); case PlayerSoundType.jump: return(AudioSources[1].isPlaying); case PlayerSoundType.falldown: return(AudioSources[2].isPlaying); case PlayerSoundType.throwcube: return(AudioSources[3].isPlaying); case PlayerSoundType.flash: return(AudioSources[4].isPlaying); case PlayerSoundType.hook: return(AudioSources[5].isPlaying); case PlayerSoundType.stoptime: return(AudioSources[6].isPlaying); case PlayerSoundType.hit: return(AudioSources[7].isPlaying); case PlayerSoundType.trampoline: return(AudioSources[8].isPlaying); case PlayerSoundType.dead: return(AudioSources[9].isPlaying); } return(false); }
public void PlayPlayerSound(PlayerSoundType type, float volume) { switch (type) { case PlayerSoundType.WALK: PlaySound(mPlayerInSandZone ? sandWalkSound : grassWalkSound, volume); break; case PlayerSoundType.RUN: PlaySound(mPlayerInSandZone ? sandRunSound : grassRunSound, volume); break; case PlayerSoundType.JUMP: PlaySound(jumpSound, volume); break; case PlayerSoundType.SNIFF: PlaySound(sniffSounds[Random.Range(0, sniffSounds.Length)], volume); break; default: break; } }