Skip to main content

RandomAudioPlayer

A class in Root.Township, the global namespace.

Client: plays a random sound from a SoundEffectSet on this object over and over, with a random delay between plays.

Constructors​

MemberWhat it is
RandomAudioPlayer()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

5 private and internal fields
MemberWhat it is
private float averageLengthSeconds added to each delay to allow for the sound's length.
private bool hasBeenDestroyedSet on destroy to stop the play loop.
private float maxDelayLongest random wait between sounds.
private float minDelayShortest random wait between sounds.
private SoundEffectSet setSound set to play from.

Methods​

3 private and internal methods
MemberWhat it is
private void OnDestroy()Marks the player destroyed so the delayed calls stop.
private void PlaySound()Plays a sound from the set and schedules the next one after a random delay plus averageLength.
private void Start()Schedules the first sound after a random delay, unless headless.