Introduction to scripts in Unity Spark
Understand how Unity Spark scripts work, how they differ from Unity Editor scripts, and what they can do.
Read time 1 minuteLast updated 3 hours ago
Scripts control your game's behavior, such as how the player moves, what happens when they collect a coin, or what a button does. Unity Spark scripts use Luau and attach to objects as components.
You don't need to use scripts to make a game, you can ask the AI assistant to create gameplay logic for you. However, if you want to write your own scripts, this section explains how they work and what they can do.
Differences from Unity Editor scripts
Unity Spark writes gameplay logic in Luau, a typed dialect of Lua, as Unity Studio scripts. Scripts work differently from scripts in the Unity Editor:
- Scripts attach to objects as components.
- Scripts aren't C#, and you don't need to compile them. They run as soon as you enter Play mode.
- Scripts use the Unity Spark scripting API, which works with the objects and components that Unity Spark provides. It doesn't expose the full Unity Engine API.
For more information, refer to Unity Spark fundamentals and Limitations of Unity Spark.
Examples of script code
Other pages include the following examples of Unity Spark script code.
Task | Code | More information |
|---|---|---|
| Load another scene | | Scenes |
| Respond to a button click | | Game UI |
Scripts can also find objects by their tag, move objects whose Rigidbody2D component uses the Kinematic body type, and change Scene Settings while the game runs, for example, to darken the sky as night falls.