Speaker API¶
Control a Speaker from a script by its name. It's server-authoritative — the platform
applies the command and tells every client, so a bell rings (or stops) at the same moment for the whole instance, and a
player who joins later hears the current state. Give the Speaker a Script Name (e.g. "bell") in the inspector, then
address it with that name.
Methods¶
Speaker.Play("bell"); // play the speaker's clip
Speaker.Stop("bell"); // stop it
Speaker.SetVolume("bell", 0.5f); // 0..1 — scales on top of the speaker's base volume + shape
bool ringing = Speaker.IsPlaying("bell");
| Call | What it does |
|---|---|
Speaker.Play(name) |
Start the named speaker's clip (synced to everyone). |
Speaker.Stop(name) |
Stop it. |
Speaker.SetVolume(name, v) |
Set a scripted volume factor 0..1. Composes with the creator base volume, the directional shape, and each player's own per-speaker slider. |
Speaker.IsPlaying(name) |
true while the named speaker is playing. |
Example — a shop bell on a trigger¶
void OnPlayerEnter() {
Speaker.Play("shop-bell");
}
Because it's server-authoritative, everyone in the shop hears the bell together — you don't have to worry about which client ran the trigger.
Late joiners¶
Whether a player who joins after a Speaker.Play hears it depends on the speaker's Loop setting — no re-firing of
things that already happened:
- Looping (ambient music, a hum) → a late joiner is caught up so they hear the ongoing loop.
- One-shot (Loop off — a bell, a knock) → plays once for whoever's present and is never replayed to late joiners.
So use a one-shot speaker for effects and a looping speaker for ambience, and late-join behaviour just works.
Directional & muffled
The speaker still projects through its shape (cone / box) and muffles off-axis — Speaker.* only controls
playback and volume, not the field. Design the field on the Speaker itself; see
Speakers & shaped audio.