Sound

The sounds of a world are the Audio Source components of its scene (sound in a world). A script plays them on the game it runs on: Play() on one player's game plays for that player. To play a sound for everyone, send a network event that each game plays, or sync a state. The server has no sound: mark these scripts [ClientOnly].

csharp
using NodeWorld.Flux;

namespace MyWorld
{
    [ClientOnly]
    public class Jukebox : FluxScript
    {
        public AudioSource speaker;
        public AudioClip[] songs;
        private int _song;

        protected override void Start() => Interaction.SetInteractable(gameObject, true);

        protected override void OnInteract()
        {
            _song = (_song + 1) % songs.Length;
            speaker.clip = songs[_song];
            speaker.Play();
        }
    }
}

Audio Source

Play(), PlayDelayed(seconds), Stop(), Pause(), UnPause(), isPlayingPlay the source's clip.
PlayOneShot(clip, volumeScale)Plays a clip over what the source plays, with its settings.
clipThe clip: a field of type AudioClip set from the scene, or the clip of another source. AudioClip.length is its length in seconds.
volume, pitch, mute, loop, playOnAwake, priority, timeAs in Unity; time is the position in the clip, in seconds.
spatialBlend, minDistance, maxDistance2D (0) or 3D (1), and how it fades with distance.
enabledTurns the source on or off.

Read what a source plays

  • GetSpectrumData(samples, channel, window): the spectrum of what the source plays (an FFT); samples.Length is a power of two from 64 to 8192, window an FFTWindow (Blackman, Hanning…).
  • GetOutputData(samples, channel): the last samples it played (the waveform), 1 to 16 384.

Pulse reads GetOutputData to make a world react to its music.

Other sounds

  • A video's sound plays through the Audio Sources you give its player (video players).
  • How players hear each other's voices: players.
  • The player's ears are the game's: an Audio Listener of your scene is removed (what a world may hold).