Getting Started
Package Types
Scene Setup
Custom Collision, Layers, and Tags
Key Differences from Standard Unity3D development
Economy
Scripting
C# Scripting
Visual Scripting
Sync and Multiplayer
Components
Environment Settings Overrides
Render Pipeline Settings Overrides
Guidelines
Supported Features and Limitations
Support
Code in a Unity project is written using C# script files. These can be created using Create/C# Script
.
By default scripts are of class MonoBehaviour
which can be attached to game objects. But Spatial also supports static
classes, ScriptableObjects
, custom class
& struct
types, and inheritance
.
<aside> <img src="/icons/warning_yellow.svg" alt="/icons/warning_yellow.svg" width="40px" /> Remember! Only scripts inside the assembly folder will be included in your sandbox and published spaces.
</aside>
Programming is easier with a nice editor. We recommend using VSCode. Setup instructions can be found at the link below.
Create a new script with Create/C# Script
inside our scripts folder and copy/paste the following code into the body of your new MonoBehaviour
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 game object as a component
using the Add Component
button or by dragging the script into the game object’s inspector. When you enter play mode, or publish your space, you should now see the object spinning!
Create a new C# script in your project and add it to an object in your scene’s hierarchy. Open the script in your favorite editor and add the following using
statement to the existing using statements:
using SpatialSys.UnitySDK;
Next, in the Start()
event, add the following line of code:
void Start()
{
SpatialBridge.coreGUIService.SetCoreGUIEnabled(SpatialCoreGUITypeFlags.Chat, false);
}
You can use the coreGUIService
to manage other Spatial UI elements to give you a bit more control over your game’s experience. The SetCoreGUIEnabled(SpatialCoreGUITypeFlags.Chat, false)
will disable Spatial’s chat and prevent users from communicating via text. See here for the other UI type flags available.
<aside>
🗒️ The SpatialBridge
is the main object that provides access to Spatial services and acts as a bridge between user code and Spatial core functionality.
</aside>
The full code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SpatialSys.UnitySDK;
public class YourScriptFileName: MonoBehaviour
{
void Start()
{
SpatialBridge.coreGUIService.SetCoreGUIEnabled(SpatialCoreGUITypeFlags.Chat, false);
}
}
You’re now ready to start adding C# to your Spatial Creator Toolkit project! You can see the Spatial Creator Toolkit C# samples for more inspiration and examples.
← Previous
Next →