UI
The scriptable slice of the UI system: showing and hiding canvases, tinting and swapping images, driving progress bars, enabling buttons, and moving elements. For building UI in the editor, see the UI guide.
Canvas
Visible
Whether the canvas is shown. Read and write.
Showing a canvas also takes input focus; hiding it hands focus back to whatever canvas is beneath. That's what makes a pause menu capture the gamepad without you wiring anything up.
GetComponent<Canvas>()!.Visible = false;Canvas.Find(string name)
Finds a canvas anywhere in the scene by its entity's name. Returns null if there's no match. This is how one script reaches a canvas it doesn't live on.
public class PauseController : GameEntity
{
private Canvas? m_Menu;
protected override void OnCreate()
{
m_Menu = Canvas.Find("PauseMenu");
}
protected override void OnUpdate(float ts)
{
if (m_Pause.WasPressedThisFrame)
{
bool paused = !m_Menu!.Visible;
m_Menu.Visible = paused;
Time.TimeScale = paused ? 0f : 1f;
}
}
}UIImage
Color
A Vector4 of red, green, blue and alpha, each 0 to 1. Read and write — the tint, and the way to fade a panel.
GetComponent<UIImage>()!.Color = new Vector4(1, 1, 1, 0.5f);Source
The image's texture, as a path relative to your Assets folder. Read and write; takes effect on the next frame's draw.
m_StatusIcon.Source = "Textures/AlertPanel.png";Works with .svg as well as bitmap formats, so an icon set can ship as vectors and stay sharp at any canvas scale.
UIProgressBar
Value
A number from 0 to 1. Read and write. A Fill child sized to match follows it automatically.
m_HealthBar.Value = m_Health / m_MaxHealth;UIButtonComponent
Interactable
Whether the button responds to clicks. Read and write — the greyed-out "Continue" on a fresh save file.
GetComponent<UIButtonComponent>()!.Interactable = SaveSystem.HasSave(0);Handling clicks
Clicks are a GameEntity override, and the script has to be on the button's own entity:
using JoystickEngine;
public class ResumeButton : GameEntity
{
protected override void OnClick()
{
Canvas.Find("PauseMenu")!.Visible = false;
Time.TimeScale = 1f;
}
}There is no OnClick +=
You can't subscribe to a button's click from a parent script. Component façades hold no state, so nothing native has a durable object to raise an event on — see Components. Put a small script on each button instead. It's more files and less indirection.
RectTransform
Position and size a UI element from script — a notification that sizes to its text, a dragged panel, a procedurally built list.
| Property | What it is |
|---|---|
AnchorMin | The rectangle's lower-left anchor, as a fraction of the parent (0–1 on each axis) |
AnchorMax | The upper-right anchor, same units |
OffsetMin | Pixel offset of the lower-left corner from AnchorMin |
OffsetMax | Pixel offset of the upper-right corner from AnchorMax |
All four are Vector2, readable and writable.
The pair of anchors is what expresses both pinning and stretching in one representation:
RectTransform rt = GetComponent<RectTransform>()!;
// Pin to the top-left corner, 200×50 pixels.
rt.AnchorMin = new Vector2(0, 1);
rt.AnchorMax = new Vector2(0, 1);
rt.OffsetMin = new Vector2(10, -60);
rt.OffsetMax = new Vector2(210, -10);
// Stretch across the full width of the parent, 40 pixels tall at the bottom.
rt.AnchorMin = new Vector2(0, 0);
rt.AnchorMax = new Vector2(1, 0);
rt.OffsetMin = new Vector2(0, 0);
rt.OffsetMax = new Vector2(0, 40);When AnchorMin and AnchorMax are equal on an axis, the element is pinned and the offsets act as position and size. When they differ, the element stretches with the parent and the offsets act as insets from each edge.
Rotation isn't here
RectTransform exposes anchors and offsets only — there's no rotation property in 0.1.0.
What isn't scriptable yet
UI Selectable, UI Slider, UI Toggle, UI Layout Group, UI Mask and UI Scroll Rect have no C# façade in 0.1.0. Configure them in the Properties panel.
The usual workaround for a slider or toggle is to build it out of parts you can drive — a UIImage for the track, a UIProgressBar for the fill, and a button script for the interaction. See UI scripting.
See also
- UI guide — canvases, anchoring, and every widget
- GameEntity — the
OnClickhook - Loc — translating labels
- Time — pausing behind a menu