Skip to main content

Scripts and fields

A world script is a C# class that derives from StageTimeBehaviour. Put one script class in each file, with the same name as the file, and add it to a GameObject like any other component.

using StageTime.SDK;
using TMPro;
using UnityEngine;

public class Scoreboard : StageTimeBehaviour
{
public TMP_Text label; // Inspector field
public Color highlight = Color.yellow;

[Synced] private int score; // shared with everyone in the room

private void Start() { label.text = "Ready"; }
}

Fields​

Inspector fields. Public and [SerializeField] fields appear in the Inspector, as usual. Supported types:

  • bool, int, float, double, string
  • Vector2, Vector3, Vector4, Quaternion, Color
  • references: GameObject, Transform, any component (e.g. TMP_Text, AudioSource), and other scripts
  • arrays of all of these

Values you set in the Inspector are applied when the world loads, before Start.

Synced fields. Mark a field [Synced] to share it with everyone in the room. See Ownership and sync.

The C# you can use​

Works
Statementsif, for, while, do, foreach, switch (on numbers and enums), break, continue, return
Methodsprivate and public methods with parameters and return values
Valueslocal variables, arrays, new int[n], new Vector3(...)
Textstring concatenation and interpolation, with number formats: $"{speed:0.0} m/s", score.ToString("000")
Mathsall arithmetic and comparison operators, Mathf, Vector2/3/4, Quaternion and Color maths
Other scriptsfields, methods and events of other scripts (Other scripts)
GenericsGetComponent<T>() and its family
Not supported (compile error)Use instead
Recursionloops
Your own generics, lambdas, LINQ, delegatesloops and methods
try / catch / throwcheck values before using them
Your own structs, properties, static fields, inheritance between your scriptsfields and methods
??, ?., is, asif (x != null)
switch on stringsif / else if
Alignment in interpolation ({x,5})number formats or padding
Changing a struct in place (v.Normalize())v = v.normalized;
tip

The compiler tells you exactly what is not supported, with the file and line, when you build the world.

Interaction text​

InteractionText (set in the Inspector, default "Use") is shown when a player points at an object whose script has Interact. Set DisableInteractive = true to turn interaction off.