Network events
A button that plays a sound and particles for everyone with SendCustomNetworkEvent, and a local timer with SendCustomEventDelayedSeconds calling a _ method that the network cannot trigger. See Network events.
NetworkEvents.cs
using StageTime.SDK;
using TMPro;
using UnityEngine;
/// <summary>
/// Ping: SendCustomNetworkEvent(All, "PingAll") plays a sound and a particle burst for everyone and counts locally.
/// Delayed: SendCustomEventDelayedSeconds runs a local-only event (name starts with '_') two seconds later.
/// </summary>
public class NetworkEvents : StageTimeBehaviour
{
public TMP_Text label;
public AudioSource sound;
public ParticleSystem burst;
private int pings;
private string delayed = "-";
private void Start()
{
Show();
}
public void Ping()
{
SendCustomNetworkEvent(NetworkEventTarget.All, "PingAll");
}
public void PingAll()
{
pings++;
if (sound != null) sound.Play();
if (burst != null) burst.Emit(40);
Show();
}
public void StartDelayed()
{
delayed = "waiting 2 s...";
Show();
SendCustomEventDelayedSeconds("_DelayedDone", 2f);
}
public void _DelayedDone()
{
delayed = "fired at " + (Mathf.Round(Time.time * 10f) / 10f) + " s";
Show();
}
private void Show()
{
if (label != null) label.text = $"Pings received: {pings}\nDelayed: {delayed}";
}
}