wiki.sine.space | sinespace

Difference between revisions of "Scripting/SGameObject"

From wiki.sine.space
Jump to: navigation, search
(Added examples to properties/member functions: AddLight, AddAudioSource, AddRigidbody, Light, Animator, Audio, Renderer, Rigidbody)
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/sgameobject")
 
(71 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The SGameObject class refers a single Game Object active within the scene.
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/sgameobject
 
+
=Members=
+
==Miscellaneous==
+
{{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|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|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|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();}}
+
 
+
==Components==
+
 
+
{{ScriptFunction|SLight|AddLight|()|Adds a Light component to the object.|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>
+
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|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|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>
+
Space.Log(obj.Light);<br>
+
''-- prints "SLight" to the console. Now we can work with the Light component on this object.''}}
+
 
+
{{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 "" 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>
+
''-- prints "SAudioSource" to the console. Now we can work with the AudioSource component on this object.''}}
+
 
+
{{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>
+
Space.Log(obj.Renderer);<br>
+
''-- prints "SRenderer" to the console if there is an Renderer component on this object, or "" if there is none.''}}
+
 
+
{{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>
+
''-- prints "SRigidbody" to the console. Now we can work with the Rigidbody component on this object.''}}
+
 
+
{{ScriptFunction|SUIText|UIText|{ get; }|Returns a reference to a UI.Text component on the object. Will return null if it does not exist.}}
+
==Events==
+
{{ScriptFunction|void|SubscribeToEvents|();|Causes this script to start listening to events on the object. Only use if you need to.}}
+
{{ScriptFunction|void|OnAwake|(Action callback)|Binds a event to the Awake() event. Requires SubscribeToEvents be called first.}}
+
{{ScriptFunction|void|OnStart|(Action callback)|Binds a event to the Start() event. Requires SubscribeToEvents be called first.}}
+
{{ScriptFunction|void|OnEnable|(Action callback)|Binds a event to the OnEnable() event. Requires SubscribeToEvents be called first.}}
+
{{ScriptFunction|void|OnDisable|(Action callback)|Binds a event to the OnDisable() event. Requires SubscribeToEvents be called first.}}
+
{{ScriptFunction|void|OnFixedUpdate|(Action callback)|Binds a event to the OnFixedUpdate() event. Requires SubscribeToEvents be called first.}}
+
{{ScriptFunction|void|OnLateUpdate|(Action callback)|Binds a event to the OnLateUpdate() 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.}}
+
==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|Children[]|{ get; }|Returns the list of direct children of this object}}
+
==Transform==
+
{{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|SQuaternion|WorldRotation|{ get; set; }|Gets or sets the current rotation of this object relative to the scene}}
+
{{ScriptFunction|SQuaternion|LocalRotation|{ get; set; }|Gets or sets the current rotation of this object relative to the parent object}}
+
{{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|Forward|{ get; }|Returns the forward direction vector of this game object (blue arrow)}}
+
{{ScriptFunction|SVector|Up|{ get; }|Returns the up direction vector of this game object (green arrow)}}
+
{{ScriptFunction|SVector|Right|{ get; }|Returns the right direction vector of this game object (red arrow)}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 07:54, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/types/sgameobject