Podium
Whoever stands on the podium is heard at the same level everywhere in the world, a little louder than normal: a stage
for hosts and announcements. Put the script on an object at the centre of the podium, set radius, and add a
TextMeshPro label if you like. Every device works out who is on the podium from where players stand, so the script
needs no synced variables. The speaker's own device does the same, which is how StageTime knows to show them a banner
saying their voice is being broadcast. See Voice.
Podium.cs
using StageTime.SDK;
using TMPro;
using UnityEngine;
/// <summary>
/// An announcer's podium: whoever stands on it is heard at the same level everywhere in the world, a little louder than
/// normal. Put it on the podium's centre object and set <c>radius</c>. Every device works out who is on the podium from
/// where players stand, so it needs no networking; the speaker's own device does the same, which is how StageTime knows
/// to show them the "everyone can hear you" banner. Shows <c>SetVoice2D</c>, <c>SetVoiceGain</c> and <c>ResetVoice</c>.
/// </summary>
public class Podium : StageTimeBehaviour
{
public TMP_Text label;
public float radius = 1f;
[Range(0f, 2f)] public float speakerGain = 1.5f;
private StageTimePlayer[] players = new StageTimePlayer[0];
private float nextCheck;
private void Update()
{
if (Time.time < nextCheck) return;
nextCheck = Time.time + 0.25f;
int count = StageTimePlayer.GetPlayerCount();
if (players.Length != count) players = new StageTimePlayer[count];
StageTimePlayer.GetPlayers(players);
string speaker = "";
for (int i = 0; i < players.Length; i++)
{
StageTimePlayer player = players[i];
if (player == null) continue;
bool onPodium = IsOnPodium(player);
if (player.GetVoice2D() == onPodium) continue;
if (onPodium)
{
player.SetVoice2D(true);
player.SetVoiceGain(speakerGain);
}
else player.ResetVoice();
}
for (int i = 0; i < players.Length; i++)
if (players[i] != null && players[i].GetVoice2D()) speaker = players[i].displayName;
if (label != null) label.text = speaker.Length > 0 ? "On air: " + speaker : "Podium\nStep up to speak to everyone";
}
private bool IsOnPodium(StageTimePlayer player)
{
Vector3 offset = player.GetPosition() - transform.position;
return offset.y > -0.5f && offset.y < 2f && offset.x * offset.x + offset.z * offset.z <= radius * radius;
}
// Everyone sounds normal again when the podium goes away (the world unloading resets this too).
private void OnDisable()
{
for (int i = 0; i < players.Length; i++)
if (players[i] != null) players[i].ResetVoice();
}
}