// Searches the array of sounds and sets the audio sources to use the correct clip void SetFootstepSound(string name) { for (int i = 0; i < footstepSounds.Length; i++) { // Surface tag should be same as the corresponding sound effect name if (footstepSounds[i].surfaceName == name) { currentSoundArray = footstepSounds[i]; } } }
// Chooses a weighted random sound from the surfaces possible footstep sounds void SetRandomSound(FootstepArray sounds) { int random = Random.Range(0, sounds.totalWeighting); for (int i = 0, current = 0; i < sounds.soundArray.Length; i++) { current += sounds.soundArray[i].weight; if (random < current) { source.clip = sounds.soundArray[i].sound; source.volume = sounds.soundArray[i].volume; return; } } }