Getting Started
Unity Package Types
Components
Economy
Scripting
Guidelines
Support
C# Scripting API Overview
C# is a versatile and powerful programming language favored for its simplicity and expressiveness, making it an ideal choice for scripting in the Spatial Creator Toolkit. Its seamless integration with Unity provides a robust environment for developers to bring interactive and immersive 3D experiences to life with efficiency and ease. Leveraging C# in this toolkit allows for rapid prototyping and iteration, opening the door to a wide range of creative possibilities in the realm of spatial development.
Unity C# Scripting Support
Most of the C# scripting that will be supported in Spatial is out-of-the-box C# scripting in Unity. This means that if you're familiar with scripting in Unity, you'll feel right at home in Spatial. If you're new to C# scripting in Unity or need a refresher, Unity's comprehensive documentation is an excellent resource.
You can learn more about C# scripting by checking out the official Unity Scripting documentation here.
While not all Unity APIs are supported, Spatial supports a very large subset that let you script your game in nearly the exact same way you would a regular Unity game. See the Limitations section below to learn more.
Project C# Assembly Setup
Create a folder for your scripts with Create/folder
, name it something like Scripts
.
Inside that folder, create an Assembly Definition with Create/Assembly Definition
.
An Assembly Definition bundles all the code inside a folder, and is what we will use to package and upload your code along with your space
In the Assembly definition inspector, make sure the name is something distinct, and consider creating a Root Namespace
to keep your code organized.
Next, open the Spatial Creator Toolkit Settings, and drag the assembly to the C# Assembly field. Now all code inside the assembly will be included when you test or publish this package.
Scripts
If you aren’t familiar, code in a Unity project is written through C# script files. These can be created at Create/C# Script
.
By default scripts are of class MonoBehavior
which can be attached to gameObjects. But Spatial also supports static
classes, ScriptableObjects
, custom class
& struct
types, and inheritance
.
Setup Your Code Environment
Programming is easier with a nice editor. We recommend using VSCode. Setup instructions can be found at the link below.
Example Script
Create a new script with Create/C# Script
inside our scripts folder and copy/paste the following code into the body of your new monoBehavior
public Vector3 rotationAngles = new Vector3(0.0f, 50.0f, 0.0f);
private void Update()
{
transform.Rotate(rotationAngles * Time.deltaTime);
}
Now, you can add your script to any gameObject as a component
using the Add Component
button or by dragging the script into the gameObjects inspector. When you enter play mode, or publish your space, you should now see the object spinning!
Limitations
Spatial Scripting API Reference
← Previous
Next →