wiki.sine.space | sinespace

Difference between revisions of "Scripting/SGameObject"

From wiki.sine.space
Jump to: navigation, search
m (Adjusted children to show the default 1-based behaviour instead of the old 0-based.)
 
(10 intermediate revisions by one other user not shown)
Line 3: Line 3:
 
=Members=
 
=Members=
 
==Miscellaneous==
 
==Miscellaneous==
{{ScriptFunction|bool|Active|{ get; set; }|Is this object Active in the scene|Object.Active = true;}}
+
{{ScriptFunction|bool|Active|{ get; set; }|Is this object Active in the scene|5= Object.Active = true;}}
 
{{ScriptFunction|int|Layer|{ get; set; }|Gets/Sets the object onto a particular layer (0-31)|Space.Log("This object is on the layer " .. Object.Layer);}}
 
{{ScriptFunction|int|Layer|{ get; set; }|Gets/Sets the object onto a particular layer (0-31)|Space.Log("This object is on the layer " .. Object.Layer);}}
 
{{ScriptFunction|string|Tag|{ get; }|Gets this objects Tag|Space.Log("Object Tag is " .. Object.Tag);}}
 
{{ScriptFunction|string|Tag|{ get; }|Gets this objects Tag|Space.Log("Object Tag is " .. Object.Tag);}}
{{ScriptFunction|string|Name|{ get; set; }|Gets/sets the name of this object|Object.Name = "Hello World!";}}
+
{{ScriptFunction|string|Name|{ get; set; }|Gets/sets the name of this object|5= Object.Name = "Hello World!";}}
 
{{ScriptFunction|bool|Exists|{ get; }|Does this object still exist in the scene (returns false if the object has been deleted via Destroy();)|if(!Object.Exists) return;}}
 
{{ScriptFunction|bool|Exists|{ get; }|Does this object still exist in the scene (returns false if the object has been deleted via Destroy();)|if(!Object.Exists) return;}}
{{ScriptFunction|SGameObject|Duplicate|();|Copies the object and returns a reference to the copy. Equivalent to calling Instantiate() in Unity|local copy = Object.Duplicate();}}
+
{{ScriptFunction|SGameObject|Duplicate|();|Copies the object and returns a reference to the copy. Equivalent to calling Instantiate() in Unity|5= local copy = Object.Duplicate();}}
 
{{ScriptFunction|void|Destroy|();|Schedules this object for deletion at the end of the frame|Object.Destroy();}}
 
{{ScriptFunction|void|Destroy|();|Schedules this object for deletion at the end of the frame|Object.Destroy();}}
  
 
==Components==
 
==Components==
{{ScriptFunction|SLight|Light|{ get; }|Returns a reference to a Light component on the object. Will return null if it does not exist.}}
+
 
{{ScriptFunction|SAnimator|Animator|{ get; }|Returns a reference to a Animator component on the object. Will return null if it does not exist.}}
+
{{ScriptFunction|SLight|AddLight|()|Adds a Light component to the object.|5=
{{ScriptFunction|SAudioSource|Audio|{ get; }|Returns a reference to a AudioSource component on the object. Will return null if it does not exist.}}
+
local obj = Space.Host.ExecutingObject;<br><br>
{{ScriptFunction|SRenderer|Renderer|{ get; }|Returns a reference to a Renderer component on the object. Will return null if it does not exist.}}
+
''-- add the Light component to the object if there is none''<br>
{{ScriptFunction|SRigidbody|Rigidbody|{ get; }|Returns a reference to a Rigidbody component on the object. Will return null if it does not exist.}}
+
if obj.Light == null then<br>
 +
:obj.AddLight();<br>
 +
end<br><br>
 +
Space.Log(obj.Light);<br>
 +
''-- prints "SLight" to the console. Now we can work with the Light component on this object.''}}
 +
 
 +
{{ScriptFunction|SAudioSource|AddAudioSource|()|Adds an AudioSource component to the object.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the AudioSource component to the object if there is none''<br>
 +
if obj.Audio == null then<br>
 +
:obj.AddAudioSource();<br>
 +
end<br><br>
 +
Space.Log(obj.Audio);<br>
 +
''-- prints "SAudioSource" to the console. Now we can work with the AudioSource component on this object.''}}
 +
 
 +
{{ScriptFunction|SClickable|AddClickable|()|Adds a Clickable component to the object.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the Clickable component to the object if there is none''<br>
 +
if obj.Clickable == null then<br>
 +
:obj.AddClickable();<br>
 +
end<br><br>
 +
Space.Log(obj.Clickable);<br>
 +
''-- prints "SClickable" to the console. Now we can work with the Clickable component on this object.''}}
 +
 
 +
{{ScriptFunction|SRigidbody|AddRigidbody|()|Adds a Rigidbody component to the object.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the Rigidbody component to the object if there is none''<br>
 +
if obj.Rigidbody == null then<br>
 +
:obj.AddRigidbody();<br>
 +
end<br><br>
 +
Space.Log(obj.Rigidbody);<br>
 +
''-- prints "SRigidbody" to the console. Now we can work with the Rigidbody component on this object.''}}
 +
 
 +
{{ScriptFunction|SNavMeshAgent|AddNavMeshAgent|()|Adds a NavMeshAgent component to the object.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the NavMeshAgent component to the object if there is none''<br>
 +
if obj.NavMeshAgent == null then<br>
 +
:obj.AddNavMeshAgent();<br>
 +
end<br><br>
 +
Space.Log(obj.NavMeshAgent);<br>
 +
''-- prints "SNavMeshAgent" to the console. Now we can work with the NavMeshAgent component on this object.''}}
 +
 
 +
{{ScriptFunction|SSeat|AddSeat|()|Adds a Seat component to the object.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the Seat component to the object if there is none''<br>
 +
if obj.Seat == null then<br>
 +
:obj.AddSeat();<br>
 +
end<br><br>
 +
Space.Log(obj.Seat);<br>
 +
''-- prints "SSeat" to the console. Now we can work with the Seat component on this object.''}}
 +
 
 +
{{ScriptFunction|SLight|Light|{ get; }|Returns a reference to a Light component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the Light component to the object if there is none''<br>
 +
if obj.Light == null then<br>
 +
:obj.AddLight ();<br>
 +
end<br><br>
 +
''-- Now we can work with the Light component on this object.''<br>
 +
''-- For example, let's set its colour to Red:''<br>
 +
obj.Light.Color = Vector.New(1,0,0);}}
 +
 
 +
{{ScriptFunction|SAnimator|Animator|{ get; }|Returns a reference to a Animator component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
Space.Log(obj.Animator);<br>
 +
''-- prints "SAnimator" to the console if there is an Animator component on this object, or an empty string, if there is none.''}}
 +
 
 +
{{ScriptFunction|SAudioSource|Audio|{ get; }|Returns a reference to a AudioSource component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the AudioSource component to the object if there is none''<br>
 +
if obj.Audio == null then<br>
 +
:obj.AddAudioSource();<br>
 +
end<br><br>
 +
Space.Log(obj.Audio);<br>
 +
''-- Now we can work with the AudioSource component on this object.''<br>
 +
''-- For example, let's set its volume to 0.25:''<br>
 +
obj.Audio.Volume = 0.25;}}
 +
 
 +
{{ScriptFunction|SBrowserSurface|Browser|{ get; }|Returns a reference to a BrowserSurface component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- If this object has a BrowserSurface component, the script will reload the page in it''<br>
 +
if obj.Browser ~= null then<br>
 +
:obj.Browser.Reload ();<br>
 +
end}}
 +
 
 +
{{ScriptFunction|SRenderer|Renderer|{ get; }|Returns a reference to a Renderer component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- If this object has a Renderer component, let's colour its material blue!''<br>
 +
if obj.Renderer ~= null then<br>
 +
:obj.Renderer.Material.SetColor("_Color", 0, 0, 1, 1);<br>
 +
end}}
 +
 
 +
{{ScriptFunction|SClickable|Clickable|{ get; }|Returns a reference to a Clickable component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the Clickable component to the object if there is none''<br>
 +
if obj.Clickable == null then<br>
 +
:obj.AddClickable();<br>
 +
end<br><br>
 +
Space.Log(obj.Clickable);<br>
 +
''--Now we can work with the Clickable component on this object.''<br>
 +
''-- Let's add an option for the object to be moved up by 1 every time that option is chosen:''<br>
 +
local deltaPos = Vector.New(0,1,0);<br><br>
 +
function MoveItUp ()
 +
:obj.WorldPosition = obj.WorldPosition + deltaPos;<br>
 +
end<br>
 +
obj.Clickable.AddExtraAction ("Move up", "Moves the object up by 1.", MoveItUp);}}
 +
 
 +
{{ScriptFunction|SRigidbody|Rigidbody|{ get; }|Returns a reference to a Rigidbody component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the Rigidbody component to the object if there is none''<br>
 +
if obj.Rigidbody == null then<br>
 +
:obj.AddRigidbody();<br>
 +
end<br><br>
 +
Space.Log(obj.Rigidbody);<br>
 +
''-- Now we can work with the Rigidbody component on this object.''<br>
 +
''-- Let's make it spin!''<br>
 +
obj.Rigidbody.UseGravity = false;<br>
 +
obj.Rigidbody.AngularDrag = 0;<br>
 +
obj.Rigidbody.AngularVelocity = Vector.New(0,Space.Math.Pi/2,0);}}
 +
 
 +
{{ScriptFunction|SCollider|Collider|{ get; }|Returns a reference to a Collider component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br>
 +
''-- If this object has a Collider component, let's make it a trigger:''<br>
 +
if obj.Collider ~= null then
 +
:obj.Collider.IsTrigger = true;
 +
end}}
 +
 
 
{{ScriptFunction|SUIText|UIText|{ get; }|Returns a reference to a UI.Text component on the object. Will return null if it does not exist.}}
 
{{ScriptFunction|SUIText|UIText|{ get; }|Returns a reference to a UI.Text component on the object. Will return null if it does not exist.}}
 +
 +
{{ScriptFunction|SNavMeshAgent|NavMeshAgent|{ get; }|Returns a reference to a NavMeshAgent component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the NavMeshAgent component to the object if there is none''<br>
 +
if obj.NavMeshAgent == null then<br>
 +
:obj.AddNavMeshAgent();<br>
 +
end<br><br>
 +
Space.Log(obj.NavMeshAgent);<br>
 +
''-- prints "SNavMeshAgent" to the console. Now we can work with the NavMeshAgent component on this object.''}}
 +
 +
{{ScriptFunction|SSeat|Seat|{ get; }|Returns a reference to a Seat component on the object. Will return null if it does not exist.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- add the Seat component to the object if there is none''<br>
 +
if obj.Seat == null then<br>
 +
:obj.AddSeat();<br>
 +
end<br><br>
 +
Space.Log(obj.Seat);<br>
 +
''-- prints "SSeat" to the console. Now we can work with the Seat component on this object.''}}
 +
 
==Events==
 
==Events==
 
{{ScriptFunction|void|SubscribeToEvents|();|Causes this script to start listening to events on the object. Only use if you need to.}}
 
{{ScriptFunction|void|SubscribeToEvents|();|Causes this script to start listening to events on the object. Only use if you need to.}}
Line 28: Line 172:
 
{{ScriptFunction|void|OnUpdate|(Action callback)|Binds a event to the OnUpdate() event. Requires SubscribeToEvents be called first.}}
 
{{ScriptFunction|void|OnUpdate|(Action callback)|Binds a event to the OnUpdate() event. Requires SubscribeToEvents be called first.}}
 
{{ScriptFunction|void|OnMouseDown|(Action callback)|Binds a event to the OnMouseDown() event. Requires SubscribeToEvents be called first.}}
 
{{ScriptFunction|void|OnMouseDown|(Action callback)|Binds a event to the OnMouseDown() event. Requires SubscribeToEvents be called first.}}
 +
 
==Hierarchy==
 
==Hierarchy==
{{ScriptFunction|SGameObject|Parent|{ get; set; }|Gets/sets the parent GameObject of this object. Assign nil/null to set this as the root.}}
+
 
{{ScriptFunction|SGameObject|Root|{ get; }|Gets the root of this object group - may be this object.}}
+
{{ScriptFunction|SGameObject|Parent|{ get; set; }|Gets/sets the parent GameObject of this object. Assign nil/null to set this as the root.|5=
{{ScriptFunction|SGameObject|Children[]|{ get; }|Returns the list of direct children of this object}}
+
''-- For this example, 2 separate Game Objects ("Cube", "Cube (1)") are used.''<br>
 +
''-- This Scripting Runtime is the component of the "Cube" object.''<br>
 +
''-- 1 Object Reference is used: Name: Cube1, references "Cube (1)".'' <br><br>
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
obj.Parent = Space.Host.GetReference("Cube1");<br>
 +
''-- Now "Cube (1)" is the parent of "Cube" (can be observed in Hierarchy).''}}
 +
 
 +
{{ScriptFunction|SGameObject|Root|{ get; }|Gets the root of this object group - may be this object.|5=
 +
''-- For this example, 3 separate Game Objects ("Cube", "Cube (1)", "Cube (2)") are used.''<br>
 +
''-- "Cube" is the parent of "Cube (1)", "Cube (1)" is the parent of "Cube (2)"''<br>
 +
''-- This Scripting Runtime is the component of the "Cube (2)" object.'' <br><br>
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
Space.Log(obj.Root.Name);<br>
 +
''-- prints "Cube" to the console''}}
 +
 
 +
{{ScriptFunction|SGameObject[]|Children|{ get; }|Returns the list of direct children of this object.|5=
 +
''-- For this example, 3 separate Game Objects ("Cube", "Cube (1)", "Cube (2)") are used.''<br>
 +
''-- "Cube" is the parent of both "Cube (1)" and "Cube (2)" (in this order in the hierarchy).''<br>
 +
''-- This Scripting Runtime is the component of the "Cube" object.'' <br><br>
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
Space.Log(obj.Children[1].Name);<br>
 +
''-- prints "Cube (1)" to the console''<br>
 +
Space.Log(obj.Children[2].Name);<br>
 +
''-- prints "Cube (2)" to the console''<br>}}
 +
 
 
==Transform==
 
==Transform==
 +
 
{{ScriptFunction|SVector|WorldPosition|{ get; set; }|Gets or sets the current position of this object relative to the scene}}
 
{{ScriptFunction|SVector|WorldPosition|{ get; set; }|Gets or sets the current position of this object relative to the scene}}
 
{{ScriptFunction|SVector|LocalPosition|{ get; set; }|Gets or sets the current position of this object relative to the objects parent, taking into account local position/scale/rotation}}
 
{{ScriptFunction|SVector|LocalPosition|{ get; set; }|Gets or sets the current position of this object relative to the objects parent, taking into account local position/scale/rotation}}
Line 39: Line 209:
 
{{ScriptFunction|SVector|LocalScale|{ get; set; }|Gets or sets the current scale of this object relative to the parent}}
 
{{ScriptFunction|SVector|LocalScale|{ get; set; }|Gets or sets the current scale of this object relative to the parent}}
 
{{ScriptFunction|SVector|WorldScale|{ get; }|Gets the current scale of this object relative to the scene}}
 
{{ScriptFunction|SVector|WorldScale|{ get; }|Gets the current scale of this object relative to the scene}}
{{ScriptFunction|SVector|Forward|{ get; }|Returns the forward direction vector of this game object (blue arrow)}}
+
{{ScriptFunction|SVector|Forward|{ get; }|Returns the forward direction vector of this game object (blue arrow)|5=
{{ScriptFunction|SVector|Up|{ get; }|Returns the up direction vector of this game object (green arrow)}}
+
local obj = Space.Host.ExecutingObject;<br><br>
{{ScriptFunction|SVector|Right|{ get; }|Returns the right direction vector of this game object (red arrow)}}
+
obj.WorldRotation = Quaternion.Euler(0,0,0);<br>
 +
Space.Log(obj.Forward);<br>
 +
''-- prints "[0,0,1]" to the console''<br>
 +
obj.WorldRotation = Quaternion.Euler(0,90,0);<br>
 +
Space.Log(obj.Forward);<br>
 +
''-- prints "[1,0,0]" to the console - now it points in the direction the Right directional vector was pointing in.''}}
 +
{{ScriptFunction|SVector|Up|{ get; }|Returns the up direction vector of this game object (green arrow)|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
obj.WorldRotation = Quaternion.Euler(0,0,0);<br>
 +
Space.Log(obj.Up);<br>
 +
''-- prints "[0,1,0]" to the console''<br>
 +
obj.WorldRotation = Quaternion.Euler(90,0,0);<br>
 +
Space.Log(obj.Up);<br>
 +
''-- prints "[0,0,1]" to the console - now it points in the direction the Forward directional vector was pointing in.''}}
 +
{{ScriptFunction|SVector|Right|{ get; }|Returns the right direction vector of this game object (red arrow)|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
obj.WorldRotation = Quaternion.Euler(0,0,0);<br>
 +
Space.Log(obj.Right);<br>
 +
''-- prints "[1,0,0]" to the console''<br>
 +
obj.WorldRotation = Quaternion.Euler(0,0,90);<br>
 +
Space.Log(obj.Right);<br>
 +
''-- prints "[0,1,0]" to the console - now it points in the direction the Up directional vector was pointing in.''}}
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Latest revision as of 03:53, 11 February 2020

The SGameObject class refers a single Game Object active within the scene.

Members

Miscellaneous

Active

bool Active { get; set; }

Is this object Active in the scene

Object.Active = true;

Layer

int Layer { get; set; }

Gets/Sets the object onto a particular layer (0-31)

Space.Log("This object is on the layer " .. Object.Layer);

Tag

string Tag { get; }

Gets this objects Tag

Space.Log("Object Tag is " .. Object.Tag);

Name

string Name { get; set; }

Gets/sets the name of this object

Object.Name = "Hello World!";

Exists

bool Exists { get; }

Does this object still exist in the scene (returns false if the object has been deleted via Destroy();)

if(!Object.Exists) return;

Duplicate

SGameObject Duplicate ();

Copies the object and returns a reference to the copy. Equivalent to calling Instantiate() in Unity

local copy = Object.Duplicate();

Destroy

void Destroy ();

Schedules this object for deletion at the end of the frame

Object.Destroy();

Components

AddLight

SLight AddLight ()

Adds a Light component to the object.

local obj = Space.Host.ExecutingObject;

-- add the Light component to the object if there is none
if obj.Light == null then

obj.AddLight();

end

Space.Log(obj.Light);

-- prints "SLight" to the console. Now we can work with the Light component on this object.

AddAudioSource

SAudioSource AddAudioSource ()

Adds an AudioSource component to the object.

local obj = Space.Host.ExecutingObject;

-- add the AudioSource component to the object if there is none
if obj.Audio == null then

obj.AddAudioSource();

end

Space.Log(obj.Audio);

-- prints "SAudioSource" to the console. Now we can work with the AudioSource component on this object.

AddClickable

SClickable AddClickable ()

Adds a Clickable component to the object.

local obj = Space.Host.ExecutingObject;

-- add the Clickable component to the object if there is none
if obj.Clickable == null then

obj.AddClickable();

end

Space.Log(obj.Clickable);

-- prints "SClickable" to the console. Now we can work with the Clickable component on this object.

AddRigidbody

SRigidbody AddRigidbody ()

Adds a Rigidbody component to the object.

local obj = Space.Host.ExecutingObject;

-- add the Rigidbody component to the object if there is none
if obj.Rigidbody == null then

obj.AddRigidbody();

end

Space.Log(obj.Rigidbody);

-- prints "SRigidbody" to the console. Now we can work with the Rigidbody component on this object.

AddNavMeshAgent

SNavMeshAgent AddNavMeshAgent ()

Adds a NavMeshAgent component to the object.

local obj = Space.Host.ExecutingObject;

-- add the NavMeshAgent component to the object if there is none
if obj.NavMeshAgent == null then

obj.AddNavMeshAgent();

end

Space.Log(obj.NavMeshAgent);

-- prints "SNavMeshAgent" to the console. Now we can work with the NavMeshAgent component on this object.

AddSeat

SSeat AddSeat ()

Adds a Seat component to the object.

local obj = Space.Host.ExecutingObject;

-- add the Seat component to the object if there is none
if obj.Seat == null then

obj.AddSeat();

end

Space.Log(obj.Seat);

-- prints "SSeat" to the console. Now we can work with the Seat component on this object.

Light

SLight Light { get; }

Returns a reference to a Light component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- add the Light component to the object if there is none
if obj.Light == null then

obj.AddLight ();

end

-- Now we can work with the Light component on this object.
-- For example, let's set its colour to Red:

obj.Light.Color = Vector.New(1,0,0);

Animator

SAnimator Animator { get; }

Returns a reference to a Animator component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

Space.Log(obj.Animator);

-- prints "SAnimator" to the console if there is an Animator component on this object, or an empty string, if there is none.

Audio

SAudioSource Audio { get; }

Returns a reference to a AudioSource component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- add the AudioSource component to the object if there is none
if obj.Audio == null then

obj.AddAudioSource();

end

Space.Log(obj.Audio);
-- Now we can work with the AudioSource component on this object.
-- For example, let's set its volume to 0.25:

obj.Audio.Volume = 0.25;

Browser

SBrowserSurface Browser { get; }

Returns a reference to a BrowserSurface component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- If this object has a BrowserSurface component, the script will reload the page in it
if obj.Browser ~= null then

obj.Browser.Reload ();
end

Renderer

SRenderer Renderer { get; }

Returns a reference to a Renderer component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- If this object has a Renderer component, let's colour its material blue!
if obj.Renderer ~= null then

obj.Renderer.Material.SetColor("_Color", 0, 0, 1, 1);
end

Clickable

SClickable Clickable { get; }

Returns a reference to a Clickable component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- add the Clickable component to the object if there is none
if obj.Clickable == null then

obj.AddClickable();

end

Space.Log(obj.Clickable);
--Now we can work with the Clickable component on this object.
-- Let's add an option for the object to be moved up by 1 every time that option is chosen:
local deltaPos = Vector.New(0,1,0);

function MoveItUp ()

obj.WorldPosition = obj.WorldPosition + deltaPos;

end

obj.Clickable.AddExtraAction ("Move up", "Moves the object up by 1.", MoveItUp);

Rigidbody

SRigidbody Rigidbody { get; }

Returns a reference to a Rigidbody component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- add the Rigidbody component to the object if there is none
if obj.Rigidbody == null then

obj.AddRigidbody();

end

Space.Log(obj.Rigidbody);
-- Now we can work with the Rigidbody component on this object.
-- Let's make it spin!
obj.Rigidbody.UseGravity = false;
obj.Rigidbody.AngularDrag = 0;

obj.Rigidbody.AngularVelocity = Vector.New(0,Space.Math.Pi/2,0);

Collider

SCollider Collider { get; }

Returns a reference to a Collider component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- If this object has a Collider component, let's make it a trigger:
if obj.Collider ~= null then

obj.Collider.IsTrigger = true;
end

UIText

SUIText UIText { get; }

Returns a reference to a UI.Text component on the object. Will return null if it does not exist.

No example provided yet

NavMeshAgent

SNavMeshAgent NavMeshAgent { get; }

Returns a reference to a NavMeshAgent component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- add the NavMeshAgent component to the object if there is none
if obj.NavMeshAgent == null then

obj.AddNavMeshAgent();

end

Space.Log(obj.NavMeshAgent);

-- prints "SNavMeshAgent" to the console. Now we can work with the NavMeshAgent component on this object.

Seat

SSeat Seat { get; }

Returns a reference to a Seat component on the object. Will return null if it does not exist.

local obj = Space.Host.ExecutingObject;

-- add the Seat component to the object if there is none
if obj.Seat == null then

obj.AddSeat();

end

Space.Log(obj.Seat);

-- prints "SSeat" to the console. Now we can work with the Seat component on this object.

Events

SubscribeToEvents

void SubscribeToEvents ();

Causes this script to start listening to events on the object. Only use if you need to.

No example provided yet

OnAwake

void OnAwake (Action callback)

Binds a event to the Awake() event. Requires SubscribeToEvents be called first.

No example provided yet

OnStart

void OnStart (Action callback)

Binds a event to the Start() event. Requires SubscribeToEvents be called first.

No example provided yet

OnEnable

void OnEnable (Action callback)

Binds a event to the OnEnable() event. Requires SubscribeToEvents be called first.

No example provided yet

OnDisable

void OnDisable (Action callback)

Binds a event to the OnDisable() event. Requires SubscribeToEvents be called first.

No example provided yet

OnFixedUpdate

void OnFixedUpdate (Action callback)

Binds a event to the OnFixedUpdate() event. Requires SubscribeToEvents be called first.

No example provided yet

OnLateUpdate

void OnLateUpdate (Action callback)

Binds a event to the OnLateUpdate() event. Requires SubscribeToEvents be called first.

No example provided yet

OnUpdate

void OnUpdate (Action callback)

Binds a event to the OnUpdate() event. Requires SubscribeToEvents be called first.

No example provided yet

OnMouseDown

void OnMouseDown (Action callback)

Binds a event to the OnMouseDown() event. Requires SubscribeToEvents be called first.

No example provided yet

Hierarchy

Parent

SGameObject Parent { get; set; }

Gets/sets the parent GameObject of this object. Assign nil/null to set this as the root.

-- For this example, 2 separate Game Objects ("Cube", "Cube (1)") are used.

-- This Scripting Runtime is the component of the "Cube" object.
-- 1 Object Reference is used: Name: Cube1, references "Cube (1)".

local obj = Space.Host.ExecutingObject;

obj.Parent = Space.Host.GetReference("Cube1");

-- Now "Cube (1)" is the parent of "Cube" (can be observed in Hierarchy).

Root

SGameObject Root { get; }

Gets the root of this object group - may be this object.

-- For this example, 3 separate Game Objects ("Cube", "Cube (1)", "Cube (2)") are used.

-- "Cube" is the parent of "Cube (1)", "Cube (1)" is the parent of "Cube (2)"
-- This Scripting Runtime is the component of the "Cube (2)" object.

local obj = Space.Host.ExecutingObject;

Space.Log(obj.Root.Name);

-- prints "Cube" to the console

Children

[[Scripting/SGameObject[]|SGameObject[]]] Children { get; }

Returns the list of direct children of this object.

-- For this example, 3 separate Game Objects ("Cube", "Cube (1)", "Cube (2)") are used.

-- "Cube" is the parent of both "Cube (1)" and "Cube (2)" (in this order in the hierarchy).
-- This Scripting Runtime is the component of the "Cube" object.

local obj = Space.Host.ExecutingObject;

Space.Log(obj.Children[1].Name);
-- prints "Cube (1)" to the console
Space.Log(obj.Children[2].Name);

-- prints "Cube (2)" to the console

Transform

WorldPosition

SVector WorldPosition { get; set; }

Gets or sets the current position of this object relative to the scene

No example provided yet

LocalPosition

SVector LocalPosition { get; set; }

Gets or sets the current position of this object relative to the objects parent, taking into account local position/scale/rotation

No example provided yet

WorldRotation

SQuaternion WorldRotation { get; set; }

Gets or sets the current rotation of this object relative to the scene

No example provided yet

LocalRotation

SQuaternion LocalRotation { get; set; }

Gets or sets the current rotation of this object relative to the parent object

No example provided yet

LocalScale

SVector LocalScale { get; set; }

Gets or sets the current scale of this object relative to the parent

No example provided yet

WorldScale

SVector WorldScale { get; }

Gets the current scale of this object relative to the scene

No example provided yet

Forward

SVector Forward { get; }

Returns the forward direction vector of this game object (blue arrow)

local obj = Space.Host.ExecutingObject;

obj.WorldRotation = Quaternion.Euler(0,0,0);
Space.Log(obj.Forward);
-- prints "[0,0,1]" to the console
obj.WorldRotation = Quaternion.Euler(0,90,0);
Space.Log(obj.Forward);

-- prints "[1,0,0]" to the console - now it points in the direction the Right directional vector was pointing in.

Up

SVector Up { get; }

Returns the up direction vector of this game object (green arrow)

local obj = Space.Host.ExecutingObject;

obj.WorldRotation = Quaternion.Euler(0,0,0);
Space.Log(obj.Up);
-- prints "[0,1,0]" to the console
obj.WorldRotation = Quaternion.Euler(90,0,0);
Space.Log(obj.Up);

-- prints "[0,0,1]" to the console - now it points in the direction the Forward directional vector was pointing in.

Right

SVector Right { get; }

Returns the right direction vector of this game object (red arrow)

local obj = Space.Host.ExecutingObject;

obj.WorldRotation = Quaternion.Euler(0,0,0);
Space.Log(obj.Right);
-- prints "[1,0,0]" to the console
obj.WorldRotation = Quaternion.Euler(0,0,90);
Space.Log(obj.Right);

-- prints "[0,1,0]" to the console - now it points in the direction the Up directional vector was pointing in.