The SGameObject class refers a single Game Object active within the scene.
Is this object Active in the scene
Gets/Sets the object onto a particular layer (0-31)
Gets this objects Tag
Gets/sets the name of this object
Does this object still exist in the scene (returns false if the object has been deleted via Destroy();)
Copies the object and returns a reference to the copy. Equivalent to calling Instantiate() in Unity
Schedules this object for deletion at the end of the frame
Adds a Light component to the object.
-- add the Light component to the object if there is none
if obj.Light == null then
end
Space.Log(obj.Light);
Adds an AudioSource component to the object.
-- add the AudioSource component to the object if there is none
if obj.Audio == null then
end
Space.Log(obj.Audio);
Adds a Clickable component to the object.
-- add the Clickable component to the object if there is none
if obj.Clickable == null then
end
Space.Log(obj.Clickable);
Adds a Rigidbody component to the object.
-- add the Rigidbody component to the object if there is none
if obj.Rigidbody == null then
end
Space.Log(obj.Rigidbody);
Adds a NavMeshAgent component to the object.
-- add the NavMeshAgent component to the object if there is none
if obj.NavMeshAgent == null then
end
Space.Log(obj.NavMeshAgent);
Adds a Seat component to the object.
-- add the Seat component to the object if there is none
if obj.Seat == null then
end
Space.Log(obj.Seat);
Returns a reference to a Light component on the object. Will return null if it does not exist.
-- add the Light component to the object if there is none
if obj.Light == null then
end
-- Now we can work with the Light component on this object.
-- For example, let's set its colour to Red:
Returns a reference to a Animator component on the object. Will return null if it does not exist.
Space.Log(obj.Animator);
Returns a reference to a AudioSource component on the object. Will return null if it does not exist.
-- add the AudioSource component to the object if there is none
if obj.Audio == null then
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;
Returns a reference to a Renderer component on the object. Will return null if it does not exist.
-- If this object has a Renderer component, let's colour its material blue!
if obj.Renderer ~= null then
Returns a reference to a Clickable component on the object. Will return null if it does not exist.
-- add the Clickable component to the object if there is none
if obj.Clickable == null then
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 ()
end
Returns a reference to a Rigidbody component on the object. Will return null if it does not exist.
-- add the Rigidbody component to the object if there is none
if obj.Rigidbody == null then
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;
Returns a reference to a Collider component on the object. Will return null if it does not exist.
-- If this object has a Collider component, let's make it a trigger:
if obj.Collider ~= null then
Returns a reference to a UI.Text component on the object. Will return null if it does not exist.
Returns a reference to a NavMeshAgent component on the object. Will return null if it does not exist.
-- add the NavMeshAgent component to the object if there is none
if obj.NavMeshAgent == null then
end
Space.Log(obj.NavMeshAgent);
Returns a reference to a Seat component on the object. Will return null if it does not exist.
-- add the Seat component to the object if there is none
if obj.Seat == null then
end
Space.Log(obj.Seat);
Causes this script to start listening to events on the object. Only use if you need to.
Binds a event to the Awake() event. Requires SubscribeToEvents be called first.
Binds a event to the Start() event. Requires SubscribeToEvents be called first.
Binds a event to the OnEnable() event. Requires SubscribeToEvents be called first.
Binds a event to the OnDisable() event. Requires SubscribeToEvents be called first.
Binds a event to the OnFixedUpdate() event. Requires SubscribeToEvents be called first.
Binds a event to the OnLateUpdate() event. Requires SubscribeToEvents be called first.
Binds a event to the OnUpdate() event. Requires SubscribeToEvents be called first.
Binds a event to the OnMouseDown() event. Requires SubscribeToEvents be called first.
Gets/sets the parent GameObject of this object. Assign nil/null to set this as the root.
-- 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");
Gets the root of this object group - may be this object.
-- "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);
Returns the list of direct children of this object.
-- "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[0].Name);
-- prints "Cube (1)" to the console
Space.Log(obj.Children[1].Name);
Gets or sets the current position of this object relative to the scene
Gets or sets the current position of this object relative to the objects parent, taking into account local position/scale/rotation
Gets or sets the current rotation of this object relative to the scene
Gets or sets the current rotation of this object relative to the parent object
Gets or sets the current scale of this object relative to the parent
Gets the current scale of this object relative to the scene
Returns the forward direction vector of this game object (blue arrow)
Returns the up direction vector of this game object (green arrow)
Returns the right direction vector of this game object (red arrow)
|