/// <summary> /// Plays a random sound from the surface the /// controller is currently over /// </summary> protected virtual void PlaySound(vp_SurfaceTypes st) { // return if there are no sounds if (st.Sounds == null || st.Sounds.Count == 0) { return; } reroll: m_SoundToPlay = st.Sounds[Random.Range(0, st.Sounds.Count)]; // get a random sound // if the sound is null, return if (m_SoundToPlay == null) { return; } // if the sound was the last sound played, reroll for another sound if (m_SoundToPlay == m_LastPlayedSound && st.Sounds.Count > 1) { goto reroll; } // set a random pitch m_Audio.pitch = Random.Range(st.RandomPitch.x, st.RandomPitch.y) * Time.timeScale; m_Audio.PlayOneShot(m_SoundToPlay); // play the sound m_LastPlayedSound = m_SoundToPlay; // cache this sound }
/// <summary> /// Plays a random sound from the surface the /// controller is currently over /// </summary> public virtual void PlaySound( vp_SurfaceTypes st ) { // return if there are no sounds if(st.Sounds == null || st.Sounds.Count == 0) return; reroll: m_SoundToPlay = st.Sounds[Random.Range(0,st.Sounds.Count)]; // get a random sound // if the sound is null, return if(m_SoundToPlay == null) return; // if the sound was the last sound played, reroll for another sound if (m_SoundToPlay == m_LastPlayedSound && st.Sounds.Count > 1) goto reroll; // set a random pitch m_Audio.pitch = Random.Range(st.RandomPitch.x, st.RandomPitch.y) * Time.timeScale; m_Audio.clip = m_SoundToPlay; m_Audio.Play(); // play the sound m_LastPlayedSound = m_SoundToPlay; // cache this sound }