Variables: coins, health and settings
Your game's values: show them, change them and react to them.
Variables are your game's values: coins, health, score, whether music is on. Your UI can show them, change them and react to them, and your Unity code can read and set them too.
Create a variable
- Click an empty part of the canvas and open the Variables tab on the right (or click the { } button in the toolbar).
- Click Add variable. A new variable appears, open for editing.
- Give it a short name like
coinsand pick its Type:
- Number: coins, health, score, level. You can also set a Range (lowest and highest value).
- Text: a player name.
- True / false: sound on, tutorial done.
- Set its Default: the value it starts with.
- Turn on Save between sessions if the game should remember it, like coins or the music setting. Unity then saves it on the player's device and loads it next time.
The small number next to each variable shows how many elements use it.
Show a variable: binding
Binding means "this property follows that variable".
- Select the element, for example the coin counter's text.
- Open its Data tab.
- Next to the property (Text, Value, Checked…), pick the variable.
For text you can mix words and values with Text template: Score {score} or Level {level} of 20.
Bars bind their Value to a number (health), toggles bind Checked to a yes/no value (musicOn), and almost anything can be bound: colours, visibility, font size and more.
Note: Some properties work both ways (marked with ⇆). When the player flips a toggle that is bound to musicOn, the variable changes too.
Change a variable: the Set Variable action
In the Actions tab, Set Variable can:
- Set to a value,
- Add, Subtract or Multiply by (numbers, like coins + 100),
- Toggle (true / false values),
- Reset to default.
React to a variable: conditions
Any interaction can have a condition, such as "only when coins ≥ 500". Use it for Buy buttons, locked levels or "Not enough coins" toasts.
Show, hide or change with several conditions (AND / OR)
In an element's Data tab, When… (conditions) gives a property one value while its conditions hold and another otherwise:
- Click Add a rule and pick the property: Visible, or any property that can be bound (a text, a number, on / off…).
- Add conditions, for example coins ≥ 100 and level > 3. Choose AND (all must hold) or OR (any one is enough).
- Set then (the value while they hold) and else.
For example: a Claim button Visible when coins ≥ 100 AND level > 3; a warning text shown when lives ≤ 1 OR time < 10. Inside a repeater card, conditions can also test the card's item fields (item.price ≤ 50). Play mode and Unity follow the rules live as the variables change.
Try it
In Play mode the Variables box in the corner shows every value live, so you can watch coins go up when you click a reward button. To test a different starting value (say, health at 10), change the variable's Default before you press Play.
In Unity
Variables are exported with your project. In code you can read and change them, and everything bound to them updates on its own:
SpaceRunnerUI.Vars.Coins.Value += 100;