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,stringVector2,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 | |
|---|---|
| Statements | if, for, while, do, foreach, switch (on numbers and enums), break, continue, return |
| Methods | private and public methods with parameters and return values |
| Values | local variables, arrays, new int[n], new Vector3(...) |
| Text | string concatenation and interpolation, with number formats: $"{speed:0.0} m/s", score.ToString("000") |
| Maths | all arithmetic and comparison operators, Mathf, Vector2/3/4, Quaternion and Color maths |
| Other scripts | fields, methods and events of other scripts (Other scripts) |
| Generics | GetComponent<T>() and its family |
| Not supported (compile error) | Use instead |
|---|---|
| Recursion | loops |
| Your own generics, lambdas, LINQ, delegates | loops and methods |
try / catch / throw | check values before using them |
| Your own structs, properties, static fields, inheritance between your scripts | fields and methods |
??, ?., is, as | if (x != null) |
switch on strings | if / 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.