# SGameObject

**成员** 149

|      |                                                             |                                                                                                                                                       |
| ---- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| 函数 | [SubscribeToEvents](#subscribetoevents)                     | Causes this script to start listening to events on the object.                                                                                        |
| 函数 | [SetSiblingIndex](#setsiblingindex)                         | Sets the sibling index.                                                                                                                               |
| 函数 | [SetAsFirstSibling](#setasfirstsibling)                     | This GameObject becomes the first Sibling                                                                                                             |
| 函数 | [SetAsLastSibling](#setaslastsibling)                       | This GameObject becomes the last Sibling                                                                                                              |
| 函数 | [Duplicate](#duplicate)                                     | Copies the object and returns a reference to the copy.                                                                                                |
| 函数 | [Instantiate](#instantiate)                                 | Copy of Duplicate() for convenience                                                                                                                   |
| 函数 | [AddHingeJoint](#addhingejoint)                             | Adds a Hinge Joint component to this Game Object and returns its reference                                                                            |
| 函数 | [AddLight](#addlight)                                       | Adds a Light component to the object.                                                                                                                 |
| 函数 | [AddAnimator](#addanimator)                                 | Adds an Animator component to this Game Object and returns its reference                                                                              |
| 函数 | [AddAudioSource](#addaudiosource)                           | Adds an AudioSource component to the object.                                                                                                          |
| 函数 | [AddClickable](#addclickable)                               | Adds a Clickable component to the object.                                                                                                             |
| 函数 | [GetScript](#getscript)                                     | Returns a Scripting Runtime component attached to this object by Component Name, or nil if none exist                                                 |
| 函数 | [GetScriptsInChildren](#getscriptsinchildren)               | Returns Scripting Runtime components attached to this object by Component Name or its children                                                        |
| 函数 | [GetScriptInChildren](#getscriptinchildren)                 | Returns a Scripting Runtime component attached to this object or its children by Component Name, or nil if none exist                                 |
| 函数 | [GetScriptInParent](#getscriptinparent)                     | Returns a Scripting Runtime component attached to this object or its parents by Component Name, or nil if none exist                                  |
| 函数 | [GetEvents](#getevents)                                     | –                                                                                                                                                     |
| 函数 | [GetAllEventsInChildren](#getalleventsinchildren)           | –                                                                                                                                                     |
| 函数 | [GetEventsInChildren](#geteventsinchildren)                 | –                                                                                                                                                     |
| 函数 | [GetEventsInParent](#geteventsinparent)                     | –                                                                                                                                                     |
| 函数 | [GetResources](#getresources)                               | –                                                                                                                                                     |
| 函数 | [GetAllResourcesInChildren](#getallresourcesinchildren)     | –                                                                                                                                                     |
| 函数 | [GetResourcesInChildren](#getresourcesinchildren)           | –                                                                                                                                                     |
| 函数 | [GetResourcesInParent](#getresourcesinparent)               | –                                                                                                                                                     |
| 函数 | [GetData](#getdata)                                         | Returns a Scripting Data component attached to this object by Component Name, or nil if none exist                                                    |
| 函数 | [GetAllDataInChildren](#getalldatainchildren)               | Returns Scripting Data components attached to this object by Component Name or its children                                                           |
| 函数 | [GetDataInChildren](#getdatainchildren)                     | Returns a Scripting Data component attached to this object or its children by Component Name, or nil if none exist                                    |
| 函数 | [GetDataInParent](#getdatainparent)                         | Returns a Scripting Data component attached to this object or its parents by Component Name, or nil if none exist                                     |
| 函数 | [AddRigidbody](#addrigidbody)                               | Adds a Rigidbody component to the object.                                                                                                             |
| 函数 | [AddNavMeshAgent](#addnavmeshagent)                         | Adds a NavMeshAgent component to the object.                                                                                                          |
| 函数 | [AddSeat](#addseat)                                         | Adds a Seat component to the object.                                                                                                                  |
| 函数 | [OnAwake](#onawake)                                         | Binds a event to the Awake() event.                                                                                                                   |
| 函数 | [OnStart](#onstart)                                         | Binds a event to the Start() event.                                                                                                                   |
| 函数 | [OnEnable](#onenable)                                       | Binds a event to the OnEnable() event.                                                                                                                |
| 函数 | [OnDisable](#ondisable)                                     | Binds a event to the OnDisable() event.                                                                                                               |
| 函数 | [OnFixedUpdate](#onfixedupdate)                             | Binds a event to the OnFixedUpdate() event.                                                                                                           |
| 函数 | [OnLateUpdate](#onlateupdate)                               | Binds a event to the OnLateUpdate() event.                                                                                                            |
| 函数 | [OnTriggerStart](#ontriggerstart)                           | When a GameObject collides with another GameObject, Unity calls OnTriggerEnter.                                                                       |
| 函数 | [OnTriggerStay](#ontriggerstay)                             | OnTriggerStay is called almost all the frames for every Collider other that is touching the trigger.                                                  |
| 函数 | [OnTriggerExit](#ontriggerexit)                             | OnTriggerExit is called when the Collider other has stopped touching the trigger.                                                                     |
| 函数 | [OnCollisionEnter](#oncollisionenter)                       | OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.                                                |
| 函数 | [OnCollisionStay](#oncollisionstay)                         | OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.                                            |
| 函数 | [OnCollisionExit](#oncollisionexit)                         | OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.                                               |
| 函数 | [OnParticleCollision](#onparticlecollision)                 | OnParticleCollision is called when a particle hits a Collider.                                                                                        |
| 函数 | [OnParticleTrigger](#onparticletrigger)                     | Binds a new event handler for the OnParticleTrigger event.                                                                                            |
| 函数 | [OnUpdate](#onupdate)                                       | Binds a event to the OnUpdate() event.                                                                                                                |
| 函数 | [OnMouseDown](#onmousedown)                                 | Binds a event to the OnMouseDown() event.                                                                                                             |
| 函数 | [OnApplicationQuit](#onapplicationquit)                     | Binds a new event handler for the On Application Quit event                                                                                           |
| 函数 | [CompareTag](#comparetag)                                   | –                                                                                                                                                     |
| 函数 | [SetParent](#setparent)                                     | Make this GameObject the child of GameObject 'other'                                                                                                  |
| 函数 | [Find](#find)                                               | Find and return a reference to GameObject with name 'name'                                                                                            |
| 函数 | [FindInChildren](#findinchildren)                           | Find and return a reference to GameObject with name 'name' including children                                                                         |
| 函数 | [Destroy](#destroy)                                         | Schedules this object for deletion at the end of the frame                                                                                            |
| 函数 | [GetComponent](#getcomponent)                               | –                                                                                                                                                     |
| 属性 | [Owner](#owner)                                             | Returns the GameObject's Owner                                                                                                                        |
| 属性 | [LocalID](#localid)                                         | Returns the GameObject's Local ID                                                                                                                     |
| 属性 | [InventoryID](#inventoryid)                                 | Return's the GameObject's InventoryID                                                                                                                 |
| 属性 | [HasStableID](#hasstableid)                                 | Returns true if GameObject has Stable ID                                                                                                              |
| 属性 | [GlobalID](#globalid)                                       | Returns the global ID of the GameObject                                                                                                               |
| 属性 | [Exists](#exists)                                           | Does this object still exist in the scene (returns false if the object has been deleted via Destroy();)                                               |
| 属性 | [HingeJoint](#hingejoint)                                   | Returns a HingeJoint component attached to this object, or nil if none exist                                                                          |
| 属性 | [Light](#light)                                             | Returns a reference to a Light component on the object.                                                                                               |
| 属性 | [ReflectionProbe](#reflectionprobe)                         | Returns a ReflectionProbe component attached to this object, or nil if none exist                                                                     |
| 属性 | [LightInChild](#lightinchild)                               | Returns a Light component attached to this object or its children, or nil if none exist                                                               |
| 属性 | [LightInParent](#lightinparent)                             | Returns a Light component attached to this object or it's parent, or nil if none exist                                                                |
| 属性 | [Animator](#animator)                                       | Returns a reference to a Animator component on the object.                                                                                            |
| 属性 | [Animation](#animation)                                     | Returns an Animation component attached to this object, or nil if none exist Animation is a legacy component and should not be confused with Animator |
| 属性 | [CanvasGroup](#canvasgroup)                                 | Returns Canvas Group component attached to this object, or nil if none exist                                                                          |
| 属性 | [Audio](#audio)                                             | Returns a reference to a AudioSource component on the object.                                                                                         |
| 属性 | [Floor](#floor)                                             | Returns a RoomFloor component attached to this object, or nil if none exist                                                                           |
| 属性 | [VoiceZone](#voicezone)                                     | Returns a VoiceZone component attached to this object, or nil if none exist                                                                           |
| 属性 | [Browser](#browser)                                         | Returns a reference to a BrowserSurface component on the object.                                                                                      |
| 属性 | [Director](#director)                                       | Returns a PlayableDirector component attached to this object, or nil if none exist                                                                    |
| 属性 | [Renderer](#renderer)                                       | Returns a reference to a Renderer component on the object.                                                                                            |
| 属性 | [Vehicle](#vehicle)                                         | Returns a Modular Vehicle component attached to this object, or nil if none exist                                                                     |
| 属性 | [PostProcessVolume](#postprocessvolume)                     | Returns a Post Process Volume component attached to this object, or nil if none exist                                                                 |
| 属性 | [Archimatix](#archimatix)                                   | Returns a Archimatix Model ("AXModel" component) - or Nil if nothing exists                                                                           |
| 属性 | [Clickable](#clickable)                                     | Returns a reference to a Clickable component on the object.                                                                                           |
| 属性 | [EmbeddedVideo](#embeddedvideo)                             | Returns an Embedded Video component attached to this object, or nil if none exist (may not work within editor)                                        |
| 属性 | [Avatar](#avatar)                                           | A reference to an Avatar component on the GameObject.                                                                                                 |
| 属性 | [AvatarAppearance](#avatarappearance)                       | Returns a AvatarAppearance component attached to this object, or nil if none exist                                                                    |
| 属性 | [Script](#script)                                           | Returns a Scripting Runtime component attached to this object, or nil if none exist                                                                   |
| 属性 | [StateMachine](#statemachine)                               | Returns a State Machine component attached to this object, or nil if none exist                                                                       |
| 属性 | [Networking](#networking)                                   | Returns a Simple Networking component attached to this object, or nil if none exists                                                                  |
| 属性 | [Events](#events)                                           | –                                                                                                                                                     |
| 属性 | [Resources](#resources)                                     | –                                                                                                                                                     |
| 属性 | [Data](#data)                                               | Returns a Scripting Data component attached to this object, or nil if none exist                                                                      |
| 属性 | [Rigidbody](#rigidbody)                                     | Returns a reference to a Rigidbody component on the object.                                                                                           |
| 属性 | [Collider](#collider)                                       | Returns a reference to a Collider component on the object.                                                                                            |
| 属性 | [BoxCollider](#boxcollider)                                 | Returns a Box Collider component attached to this object, or nil if none exist                                                                        |
| 属性 | [SphereCollider](#spherecollider)                           | Returns a Sphere Collider component attached to this object, or nil if none exist                                                                     |
| 属性 | [CapsuleCollider](#capsulecollider)                         | Returns a Capsule Collider component attached to this object, or nil if none exist                                                                    |
| 属性 | [WheelCollider](#wheelcollider)                             | Returns a WheelCollider component attached to this object, or nil if none exist                                                                       |
| 属性 | [CharacterController](#charactercontroller)                 | Returns a Character Controller component attached to this object, or nil if none exist                                                                |
| 属性 | [AudioReactive](#audioreactive)                             | Returns the first Audio Reactive component attached to this object, or nil if none exist                                                              |
| 属性 | [AttachmentHelper](#attachmenthelper)                       | Returns the first Attachment Helper component attached to this object, or nil if none exist                                                           |
| 属性 | [AudioReactiveAnimation](#audioreactiveanimation)           | Returns the first Audio Reactive Animation component attached to this object, or nil if none exist                                                    |
| 属性 | [AudioReactiveLight](#audioreactivelight)                   | Returns the first Audio Reactive Light component attached to this object, or nil if none exist                                                        |
| 属性 | [AudioReactiveParticleSystem](#audioreactiveparticlesystem) | Returns the first Audio Reactive Particle System component attached to this object, or nil if none exist                                              |
| 属性 | [AudioReactiveMaterial](#audioreactivematerial)             | Returns the first Audio Reactive Material component attached to this object, or nil if none exist                                                     |
| 属性 | [AudioReactiveTransform](#audioreactivetransform)           | Returns the first Audio Reactive Transform component attached to this object, or nil if none exist                                                    |
| 属性 | [TrailRenderer](#trailrenderer)                             | Returns a Trail Renderer component attached to this object, or nil if none exist                                                                      |
| 属性 | [LineRenderer](#linerenderer)                               | Returns a Line Renderer component attached to this object, or nil if none exist                                                                       |
| 属性 | [UILayout](#uilayout)                                       | Returns a Renderer component attached to this object, or nil if none exist                                                                            |
| 属性 | [UIToggle](#uitoggle)                                       | Returns a Unity uGUI Toggle component attached to this object, or nil if none exist                                                                   |
| 属性 | [UIDropdown](#uidropdown)                                   | Returns a Unity uGUI Dropdown component attached to this object, or nil if none exist                                                                 |
| 属性 | [UIButton](#uibutton)                                       | Returns a Unity uGUI Dropdown component attached to this object, or nil if none exist                                                                 |
| 属性 | [UIText](#uitext)                                           | Returns a reference to a UI.Text component on the object.                                                                                             |
| 属性 | [UISlider](#uislider)                                       | Returns a Unity uGUI Slider component attached to this object, or nil if none exist                                                                   |
| 属性 | [UIScrollbar](#uiscrollbar)                                 | Returns a Unity uGUI Scrollbar component attached to this object, or nil if none exist                                                                |
| 属性 | [UICanvas](#uicanvas)                                       | Returns a Unity uGUI Canvas component attached to this object, or nil if none exist                                                                   |
| 属性 | [UIImage](#uiimage)                                         | Returns a Unity uGUI Image component attached to this object, or nil if none exist                                                                    |
| 属性 | [UIRawImage](#uirawimage)                                   | Returns a Unity uGUI Text component attached to this object, or nil if none exist                                                                     |
| 属性 | [UIInputField](#uiinputfield)                               | Returns a Unity uGUI Text component attached to this object, or nil if none exist                                                                     |
| 属性 | [UIToolTipHint](#uitooltiphint)                             | –                                                                                                                                                     |
| 属性 | [Camera](#camera)                                           | –                                                                                                                                                     |
| 属性 | [VirtualCamera](#virtualcamera)                             | Returns a VirtualCamera component attached to this object, or nil if none exists                                                                      |
| 属性 | [Cloth](#cloth)                                             | Returns a Cloth component attached to this object, or nil if none exists                                                                              |
| 属性 | [MeshRenderer](#meshrenderer)                               | Returns a MeshRenderer component attached to this object, or nil if none exists                                                                       |
| 属性 | [Furniture](#furniture)                                     | Returns a Furniture component attached to this object, or nil if none exists                                                                          |
| 属性 | [NavMeshAgent](#navmeshagent)                               | Adds a NavMeshAgent component to the object.                                                                                                          |
| 属性 | [NavMeshObstacle](#navmeshobstacle)                         | Returns a NavMeshObstacle component attached to this object, or nil if none exists                                                                    |
| 属性 | [ParticleSystem](#particlesystem)                           | Returns a ParticleSystem component attached to this object, or nil if none exists                                                                     |
| 属性 | [RectTransform](#recttransform)                             | Returns a RectTransform component attached to this object, or nil if none exists                                                                      |
| 属性 | [Seat](#seat)                                               | Returns a reference to a Seat component on the object.                                                                                                |
| 属性 | [SkinnedMeshRenderer](#skinnedmeshrenderer)                 | Returns a SkinnedMeshRenderer component attached to this object, or nil if none exists                                                                |
| 属性 | [Radio](#radio)                                             | Returns a SceneBackgroundMusic component attached to this object, or nil if none exists                                                               |
| 属性 | [Terrain](#terrain)                                         | Returns a Terrain component attached to this object, or nil if none exists                                                                            |
| 属性 | [AnalyticsEvent](#analyticsevent)                           | –                                                                                                                                                     |
| 属性 | [GraphicRaycaster](#graphicraycaster)                       | –                                                                                                                                                     |
| 属性 | [ContentSizeFitter](#contentsizefitter)                     | –                                                                                                                                                     |
| 属性 | [Active](#active)                                           | Is this object Active in the scene                                                                                                                    |
| 属性 | [ActiveSelf](#activeself)                                   | Returns true if GameObject is Active (even if it's parent is not active)                                                                              |
| 属性 | [Layer](#layer)                                             | Gets/Sets the object onto a particular layer (0-31)                                                                                                   |
| 属性 | [Tag](#tag)                                                 | Gets this objects Tag                                                                                                                                 |
| 属性 | [Name](#name)                                               | Gets/sets the name of this object                                                                                                                     |
| 属性 | [Moniker](#moniker)                                         | –                                                                                                                                                     |
| 属性 | [Parent](#parent)                                           | Gets/sets the parent GameObject of this object.                                                                                                       |
| 属性 | [Root](#root)                                               | Gets the root of this object group - may be this object.                                                                                              |
| 属性 | [Children](#children)                                       | Returns the list of direct children of this object.                                                                                                   |
| 属性 | [WorldPosition](#worldposition)                             | Gets or sets the current position of this object relative to the scene                                                                                |
| 属性 | [LocalPosition](#localposition)                             | Gets or sets the current position of this object relative to the objects parent, taking into account local position/scale/rotation                    |
| 属性 | [WorldRotation](#worldrotation)                             | Gets or sets the current rotation of this object relative to the scene                                                                                |
| 属性 | [LocalRotation](#localrotation)                             | Gets or sets the current rotation of this object relative to the parent object                                                                        |
| 属性 | [LocalScale](#localscale)                                   | Gets or sets the current scale of this object relative to the parent                                                                                  |
| 属性 | [WorldScale](#worldscale)                                   | Gets the current scale of this object relative to the scene                                                                                           |
| 属性 | [Forward](#forward)                                         | Returns the forward direction vector of this game object (blue arrow)                                                                                 |
| 属性 | [Up](#up)                                                   | Returns the up direction vector of this game object (green arrow)                                                                                     |
| 属性 | [Right](#right)                                             | Returns the right direction vector of this game object (red arrow)                                                                                    |
| 属性 | [EventCalendar](#eventcalendar)                             | Returns an EventCalendar component attached to this object, or nil if none exists                                                                     |

## 函数

### SubscribeToEvents

void SubscribeToEvents()

Causes this script to start listening to events on the object.

信息

***This function is now automatically called by events that require it***

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.SubscribeToEvents()

```

### SetSiblingIndex

void SetSiblingIndex(int newIndex)

Sets the sibling index.

Use this to change the sibling index of the GameObject. If a GameObject shares a parent with other GameObjects and are on the same level (i.e. they share the same direct parent), these GameObjects are known as siblings. The sibling index shows where each GameObject sits in this sibling hierarchy.

Use SetSiblingIndex to change the GameObject’s place in this hierarchy. When the sibling index of a GameObject is changed, its order in the Hierarchy window will also change.

参数

| 名称     | 类型 | 默认值 |
| -------- | ---- | ------ |
| newIndex | int  | –      |

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.SetSiblingIndex(2)

```

### SetAsFirstSibling

void SetAsFirstSibling()

This GameObject becomes the first Sibling

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.SetAsFirstSibling()

```

### SetAsLastSibling

void SetAsLastSibling()

This GameObject becomes the last Sibling

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.SetAsLastSibling()

```

### Duplicate

SGameObject Duplicate()

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

返回值

`SGameObject`

示例

**Lua**

```lua
local copy = Space.Host.ExecutingObject.Duplicate()

```

**Lua**

```lua
--this script will make this object, once clicked, duplicate itself, then the duplicate
--moves up and then duplicate itself again and the duplicate move down (total 3 vertically aligned)
--(Example: cells multiplying)


thisGameObject = Space.Host.ExecutingObject


OnClick = function()

local firstDuplicate = thisGameObject.Duplicate()
firstDuplicate.WorldPosition = firstDuplicate.WorldPosition + firstDuplicate.Up
local secondDuplicate = thisGameObject.Duplicate()
secondDuplicate.WorldPosition = secondDuplicate.WorldPosition - secondDuplicate.Up

end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip="Click to watch me multiply "
thisGameObject.Clickable.OnClick(OnClick)

```

### Instantiate

SGameObject Instantiate()

Copy of Duplicate() for convenience

返回值

`SGameObject`

示例

**Lua**

```lua
NewGameObject = Space.Host.ExecutingObject.Instantiate()

```

**Lua**

```lua
--this script will make this object, once clicked, duplicate itself, then the duplicate
--moves up and then duplicate itself again and the duplicate move down (total 3 vertically aligned)
--(Example: cells multiplying)


thisGameObject = Space.Host.ExecutingObject


OnClick = function()

local firstDuplicate = thisGameObject.Instantiate()
firstDuplicate.WorldPosition = firstDuplicate.WorldPosition + firstDuplicate.Up
local secondDuplicate = thisGameObject.Instantiate()
secondDuplicate.WorldPosition = secondDuplicate.WorldPosition - secondDuplicate.Up

end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip="Click to watch me multiply "
thisGameObject.Clickable.OnClick(OnClick) 

```

### AddHingeJoint

[SHingeJoint](/docs/zh-Hans/scripting/client-scripting-api-reference/components/shingejoint.md) AddHingeJoint()

Adds a Hinge Joint component to this Game Object and returns its reference

返回值

`SHingeJoint`

示例

**Lua**

```lua
NewHingeJoint = Space.Host.ExecutingObject.AddHingeJoint()

```

**Lua**

```lua
--clicking this object will add a Hinge Joint component to it at runtime

thisObject = Space.Host.ExecutingObject


OnClick = function()
HJ = thisObject.AddHingeJoint()
end



thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### AddLight

[SLight](/docs/zh-Hans/scripting/client-scripting-api-reference/components/slight.md) AddLight()

Adds a Light component to the object.

返回值

`SLight`

示例

**Lua**

```lua
newLightComponent = Space.Host.ExecutingObject.AddLight()

```

### AddAnimator

[SAnimator](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sanimator.md) AddAnimator()

Adds an Animator component to this Game Object and returns its reference

返回值

`SAnimator`

示例

**Lua**

```lua
NewAnimator = Space.Host.ExecutingObject.AddAnimator()

```

**Lua**

```lua
--clicking this object will add an animator to it and controller at runtime

thisObject = Space.Host.ExecutingObject
theResource = Space.GetResource("An Animator Controller") -- add controller to resources in Scripting Runtime


OnClick = function()
Animator = thisObject.AddAnimator()  
Animator.Controller = theResource
end



thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### AddAudioSource

[SAudioSource](/docs/zh-Hans/scripting/client-scripting-api-reference/components/saudiosource.md) AddAudioSource()

Adds an AudioSource component to the object.

返回值

`SAudioSource`

示例

**Lua**

```lua
newAudioSourceComponent = Space.Host.ExecutingObject.AddAudioSource()

```

### AddClickable

[SClickable](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sclickable.md) AddClickable()

Adds a Clickable component to the object.

返回值

`SClickable`

示例

**Lua**

```lua
newClikcableComponent = Space.Host.ExecutingObject.AddClickable()

```

### GetScript

[SScriptingRuntime](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingruntime.md) GetScript(string name)

Returns a Scripting Runtime component attached to this object by Component Name, or nil if none exist

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SScriptingRuntime`

示例

**Lua**

```lua
scriptingRuntime = Space.Host.ExecutingObject.GetScript("scriptingruntimecomponentname")

```

### GetScriptsInChildren

List< [SScriptingRuntime](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingruntime.md) > GetScriptsInChildren(string name, bool includeInactive = false)

Returns Scripting Runtime components attached to this object by Component Name or its children

参数

| 名称            | 类型   | 默认值 |
| --------------- | ------ | ------ |
| name            | string | –      |
| includeInactive | bool   | false  |

返回值

`List< SScriptingRuntime >`

示例

**Lua**

```lua
tableScriptsInChildren = Space.Host.ExecutingObject.GetScriptsInChildren("scriptingruntimecomponentname",true)

```

### GetScriptInChildren

[SScriptingRuntime](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingruntime.md) GetScriptInChildren(string name, bool includeInactive = false)

Returns a Scripting Runtime component attached to this object or its children by Component Name, or nil if none exist

参数

| 名称            | 类型   | 默认值 |
| --------------- | ------ | ------ |
| name            | string | –      |
| includeInactive | bool   | false  |

返回值

`SScriptingRuntime`

示例

**Lua**

```lua
scriptingRuntimeInChildren = Space.Host.ExecutingObject.GetScriptInChildren("scriptingruntimecomponentname",true)

```

### GetScriptInParent

[SScriptingRuntime](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingruntime.md) GetScriptInParent(string name)

Returns a Scripting Runtime component attached to this object or its parents by Component Name, or nil if none exist

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SScriptingRuntime`

示例

**Lua**

```lua
scriptingRuntimeInParent = Space.Host.ExecutingObject.GetScript("scriptingruntimecomponentname")

```

### GetEvents

[SScriptingEvents](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingevents.md) GetEvents(string name)

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SScriptingEvents`

示例

**Lua**

```lua
scriptingEvent = Space.Host.ExecutingObject.GetEvents('ScriptingEventsComponentName')

```

### GetAllEventsInChildren

List< [SScriptingEvents](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingevents.md) > GetAllEventsInChildren(string name, bool includeInactive = false)

参数

| 名称            | 类型   | 默认值 |
| --------------- | ------ | ------ |
| name            | string | –      |
| includeInactive | bool   | false  |

返回值

`List< SScriptingEvents >`

示例

**Lua**

```lua
tableScriptingEvent = Space.Host.ExecutingObject.GetAllEventsInChildren

```

### GetEventsInChildren

[SScriptingEvents](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingevents.md) GetEventsInChildren(string name, bool includeInactive = false)

参数

| 名称            | 类型   | 默认值 |
| --------------- | ------ | ------ |
| name            | string | –      |
| includeInactive | bool   | false  |

返回值

`SScriptingEvents`

示例

**Lua**

```lua
scriptingEvent = Space.Host.ExecutingObject.GetEventsInChildren('ScriptingEventsComponentName')
--or
scriptingEvent = Space.Host.ExecutingObject.GetEventsInChildren('ScriptingEventsComponentName', true)

```

### GetEventsInParent

[SScriptingEvents](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingevents.md) GetEventsInParent(string name)

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SScriptingEvents`

示例

**Lua**

```lua
scriptingEvent = Space.Host.ExecutingObject.GetEventsInParent('ScriptingEventsComponentName')

```

### GetResources

[SScriptingResources](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingresources.md) GetResources(string name)

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SScriptingResources`

示例

**Lua**

```lua
Space.Host.ExecutingObject.GetResources('ResourcesComponentName')

```

### GetAllResourcesInChildren

List< [SScriptingResources](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingresources.md) > GetAllResourcesInChildren(string name, bool includeInactive = false)

参数

| 名称            | 类型   | 默认值 |
| --------------- | ------ | ------ |
| name            | string | –      |
| includeInactive | bool   | false  |

返回值

`List< SScriptingResources >`

示例

**Lua**

```lua
tableScriptingResources = Space.Host.ExecutingObject.GetAllResourcesInChildren('ScriptingResourcesComponentName')
--or
tableScriptingResources = Space.Host.ExecutingObject.GetAllResourcesInChildren('ScriptingResourcesComponentName', true)

```

### GetResourcesInChildren

[SScriptingResources](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingresources.md) GetResourcesInChildren(string name, bool includeInactive = false)

参数

| 名称            | 类型   | 默认值 |
| --------------- | ------ | ------ |
| name            | string | –      |
| includeInactive | bool   | false  |

返回值

`SScriptingResources`

示例

**Lua**

```lua
tableScriptingResources = Space.Host.ExecutingObject.GetResourcesInChildren('ScriptingResourcesComponentName')
--or
tableScriptingResources = Space.Host.ExecutingObject.GetResourcesInChildren('ScriptingResourcesComponentName', true)

```

### GetResourcesInParent

[SScriptingResources](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingresources.md) GetResourcesInParent(string name)

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SScriptingResources`

示例

**Lua**

```lua
tableScriptingResources = Space.Host.ExecutingObject.GetResourcesInParent('ScriptingResourcesComponentName')

```

### GetData

[SScriptingData](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingdata.md) GetData(string name)

Returns a Scripting Data component attached to this object by Component Name, or nil if none exist

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SScriptingData`

示例

**Lua**

```lua
scriptingData = Space.Host.ExecutingObject.GetData("scriptingdatacomponentname")

```

### GetAllDataInChildren

List< [SScriptingData](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingdata.md) > GetAllDataInChildren(string name, bool includeInactive = false)

Returns Scripting Data components attached to this object by Component Name or its children

参数

| 名称            | 类型   | 默认值 |
| --------------- | ------ | ------ |
| name            | string | –      |
| includeInactive | bool   | false  |

返回值

`List< SScriptingData >`

示例

**Lua**

```lua
tableScriptingDataInChildren = Space.Host.ExecutingObject.GetAllDataInChildren("scriptingdatacomponentname",true)

```

### GetDataInChildren

[SScriptingData](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingdata.md) GetDataInChildren(string name, bool includeInactive = false)

Returns a Scripting Data component attached to this object or its children by Component Name, or nil if none exist

参数

| 名称            | 类型   | 默认值 |
| --------------- | ------ | ------ |
| name            | string | –      |
| includeInactive | bool   | false  |

返回值

`SScriptingData`

示例

**Lua**

```lua
scriptingDataInChildren = Space.Host.ExecutingObject.GetDataInChildren("scriptingdatacomponentname",true)

```

### GetDataInParent

[SScriptingData](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingdata.md) GetDataInParent(string name)

Returns a Scripting Data component attached to this object or its parents by Component Name, or nil if none exist

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SScriptingData`

示例

**Lua**

```lua
scriptingDataInParent = Space.Host.ExecutingObject.GetDataInParent("scriptingdatacomponentname")

```

### AddRigidbody

[SRigidbody](/docs/zh-Hans/scripting/client-scripting-api-reference/components/srigidbody.md) AddRigidbody()

Adds a Rigidbody component to the object.

返回值

`SRigidbody`

示例

**Lua**

```lua
newRigibodyComponent = Space.Host.ExecutingObject.AddRigidbody()

```

### AddNavMeshAgent

[SNavMeshAgent](/docs/zh-Hans/scripting/client-scripting-api-reference/components/snavmeshagent.md) AddNavMeshAgent()

Adds a NavMeshAgent component to the object.

返回值

`SNavMeshAgent`

示例

**Lua**

```lua
newNavMeshAgentComponent =  Space.Host.ExecutingObject.AddNavMeshAgent()

```

### AddSeat

[SSeat](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sseat.md) AddSeat()

Adds a Seat component to the object.

返回值

`SSeat`

示例

**Lua**

```lua
newSeatComponent = Space.Host.ExecutingObject.AddSeat()

```

### OnAwake

void OnAwake(Closure e)

Binds a event to the Awake() event.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function F()
Space.Log("bound")
end
Space.Host.ExecutingObject.OnAwake(F)

```

### OnStart

void OnStart(Closure e)

Binds a event to the Start() event.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function F()
Space.Log("bound")
end
Space.Host.ExecutingObject.OnStart(F)

```

### OnEnable

void OnEnable(Closure e)

Binds a event to the OnEnable() event.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function F()
Space.Log("bound")
end
Space.Host.ExecutingObject.OnEnable(F)

```

### OnDisable

void OnDisable(Closure e)

Binds a event to the OnDisable() event.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function F()
Space.Log("bound")
end
Space.Host.ExecutingObject.OnDisable(F)

```

### OnFixedUpdate

void OnFixedUpdate(Closure e)

Binds a event to the OnFixedUpdate() event.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function F()
Space.Log("bound")
end
Space.Host.ExecutingObject.OnFixedUpdate(F)

```

**Lua**

```lua
--this script will make this object move forward each physics frame
thisObject = Space.Host.ExecutingObject

OnFixedUpdate = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (thisObject.Forward * 0.01 )
--unlike OnUpdate we did not multiply by Space.DeltaTime 
--because OnFixedUpdate executes at the same rate regardless
end


thisObject.OnFixedUpdate(OnFixedUpdate)

```

### OnLateUpdate

void OnLateUpdate(Closure e)

Binds a event to the OnLateUpdate() event.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function F()
Space.Log("bound")
end
Space.Host.ExecutingObject.OnLateUpdate(F)

```

**Lua**

```lua
--this script will make this object move forward each frame
--but it will be last to move among other objects (read about OnLateUpdate)
--(example: camera movement)
thisObject = Space.Host.ExecutingObject

OnLateUpdate = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (thisObject.Forward * 0.01 * Space.DeltaTime)
--we multipy by Space.DeltaTime so that it behaves the same for all players
--even though they have different FPS (frames per second)
end


thisObject.OnLateUpdate(OnLateUpdate)

```

### OnTriggerStart

void OnTriggerStart(Action< SGameObject > e)

void OnTriggerStart(Closure e)

When a GameObject collides with another GameObject, Unity calls OnTriggerEnter.

OnTriggerEnter happens on the FixedUpdate function when two GameObjects collide. The Colliders involved are not always at the point of initial contact.

Note: Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.

参数

| 名称 | 类型                  | 默认值 |
| ---- | --------------------- | ------ |
| e    | Action< SGameObject > | –      |
| e    | Closure               | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnTriggerStart  = function(SGameObject)
 Space.Log("Trigger Start")
end

this.OnTriggerStart (OnTriggerStart )

```

**Lua**

```lua
 --the below scipt makes this object a boundary area where flying gets blocked
--while player is in it and flying is allowed once player leaves it
--(Example: No fly zone)
--[This object's collider needs to be set as IsTrigger (Please read about OnTriggerStart for troubleshooting)]

thisGameObject = Space.Host.ExecutingObject

OnTriggerStart = function(TriggerStarter)
  if TriggerStarter.Root.Avatar ~= nil then
    if TriggerStarter.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then
      Space.Scene.PlayerAvatar.BlockFly = true
    end
  end
end


OnTriggerExit = function(TriggerExiter)
  if TriggerExiter.Root.Avatar ~= nil then
    if TriggerExiter.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then
      Space.Scene.PlayerAvatar.BlockFly = false
    end
  end
end

thisGameObject.OnTriggerStart(OnTriggerStart)
thisGameObject.OnTriggerExit(OnTriggerExit) 

```

### OnTriggerStay

void OnTriggerStay(Action< SGameObject > e)

void OnTriggerStay(Closure e)

OnTriggerStay is called almost all the frames for every Collider other that is touching the trigger. The function is on the physics timer so it won't necessarily run every frame.

This message is sent to the trigger and the collider that touches the trigger. Note that trigger events are only sent if one of the colliders also has a rigidbody attached. Trigger events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions.

参数

| 名称 | 类型                  | 默认值 |
| ---- | --------------------- | ------ |
| e    | Action< SGameObject > | –      |
| e    | Closure               | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnTriggerStay  = function(SGameObject)
 Space.Log("Trigger Stay")
end

this.OnTriggerStay(OnTriggerStay)

```

**Lua**

```lua
--the below scipt makes this object a boundary area where any user entering it
--will be blocked from movement for 10 seconds, then the object will release controls and
--destry itself after that
--(Example: freezing trap)
--[This object's collider needs to be set as IsTrigger (Please read about OnTriggerStart for troubleshooting)]

thisGameObject = Space.Host.ExecutingObject
FrozenTime = 0.0

OnTriggerStart = function(TriggerStarter)
  if TriggerStarter.Root.Avatar ~= nil then
    if TriggerStarter.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then
      Space.Scene.PlayerAvatar.BlockMovement = true
    end
  end
end

OnTriggerStay = function(TriggerStayer)
  if TriggerStayer.Root.Avatar ~= nil then
    if TriggerStayer.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then
      FrozenTime = FrozenTime + Space.DeltaTime
        if FrozenTime > 20 then
        Space.Scene.PlayerAvatar.BlockMovement = false
        thisGameObject.Destroy()
        end
    end
  end
end

thisGameObject.OnTriggerStart(OnTriggerStart)
thisGameObject.OnTriggerStay(OnTriggerStay)

```

### OnTriggerExit

void OnTriggerExit(Action< SGameObject > e)

void OnTriggerExit(Closure e)

OnTriggerExit is called when the Collider other has stopped touching the trigger.

This message is sent to the trigger and the Collider that touches the trigger. Notes: Trigger events are only sent if one of the Colliders also has a Rigidbody attached. Trigger events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. OnTriggerExit occurs on the FixedUpdate after the Colliders have stopped touching. The Colliders involved are not guaranteed to be at the point of initial separation.

参数

| 名称 | 类型                  | 默认值 |
| ---- | --------------------- | ------ |
| e    | Action< SGameObject > | –      |
| e    | Closure               | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnTriggerExit  = function(SGameObject)
 Space.Log("Trigger Stay")
end

this.OnTriggerExit(OnTriggerExit)

```

**Lua**

```lua
--the below scipt makes this object a boundary area where flying gets blocked
--while player is in it and flying is allowed once player leaves it
--(Example: No fly zone)
--[This object's collider needs to be set as IsTrigger (Please read about OnTriggerStart for troubleshooting)]

thisGameObject = Space.Host.ExecutingObject

OnTriggerStart = function(TriggerStarter)
  if TriggerStarter.Root.Avatar ~= nil then
    if TriggerStarter.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then
      Space.Scene.PlayerAvatar.BlockFly = true
    end
  end
end


OnTriggerExit = function(TriggerExiter)
  if TriggerExiter.Root.Avatar ~= nil then
    if TriggerExiter.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then
      Space.Scene.PlayerAvatar.BlockFly = false
    end
  end
end

thisGameObject.OnTriggerStart(OnTriggerStart)
thisGameObject.OnTriggerExit(OnTriggerExit)

```

### OnCollisionEnter

void OnCollisionEnter(Action< SPhysicsHit > e)

void OnCollisionEnter(Closure e)

OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

In contrast to [*OnTrigger*](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sgameobject.md#ontriggerstart)[*Start*](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sgameobject.md#ontriggerstart), OnCollisionEnter is passed the [*SPhysicsHit*](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sphysicshit.md) class and not a Collider (GameObject). The SPhysicsHit class contains information, for example, about contact points and impact velocity. Notes: Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. Collision events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions.

参数

| 名称 | 类型                  | 默认值 |
| ---- | --------------------- | ------ |
| e    | Action< SPhysicsHit > | –      |
| e    | Closure               | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnCollisionEnter = function(SPhysicsHit)
 Space.Log("Collision Enter")
end

this.OnCollisionEnter(OnCollisionEnter)

```

**Lua**

```lua
 --this script will make this object delete itself if it collides with something
--(Example: grenade)
--[Make sure you add a rigibody to this object (read above about "collisions")


thisGameObject = Space.Host.ExecutingObject


OnCollisionEnter = function(SPhysicsHit)
 thisGameObject.Destroy()
end

thisGameObject.OnCollisionEnter(OnCollisionEnter) 

```

### OnCollisionStay

void OnCollisionStay(Action< [SPhysicsHit](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sphysicshit.md) > e)

void OnCollisionStay(Closure e)

OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.

In contrast to [*OnTriggerStay*](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sgameobject.md#ontriggerstay), OnCollisionStay is passed the [*SPhysicsHit*](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sphysicshit.md) class and not a Collider (GameObject). The [*SPhysicsHit*](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sphysicshit.md) class contains information about contact points, impact velocity etc. If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Notes: Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. Collision events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. Collision stay events are not sent for sleeping Rigidbodies.

参数

| 名称 | 类型                                                                                                 | 默认值 |
| ---- | ---------------------------------------------------------------------------------------------------- | ------ |
| e    | Action< [SPhysicsHit](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sphysicshit.md) > | –      |
| e    | Closure                                                                                              | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnCollisionStay = function(SPhysicsHit)
 Space.Log("Collision Stay")
end

this.OnCollisionStay(OnCollisionStay)

```

**Lua**

```lua
  --this script will make this object delete itself if
 --it is being touched for around 10 seconds
--(Example: a flag being captured)
--[Make sure this object has collider/rigidbody (read above about "collisions" for troubleshooting)]


thisGameObject = Space.Host.ExecutingObject
touchedTime = 0.0

OnCollisionStay = function(SPhysicsHit)
  touchedTime = touchedTime + Space.DeltaTime
    if touchedTime > 25 then
   thisGameObject.Destroy()
   end
end

thisGameObject.OnCollisionStay(OnCollisionStay)  

```

### OnCollisionExit

void OnCollisionExit(Action< [SPhysicsHit](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sphysicshit.md) > e)

void OnCollisionExit(Closure e)

OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.

In contrast to OnTriggerExit, OnCollisionExit is passed the SPhysicsHit class and not a Collider. The SPhysicsHit class contains information about contact points, impact velocity etc. If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Notes: Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. Collision events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions.

参数

| 名称 | 类型                                                                                                 | 默认值 |
| ---- | ---------------------------------------------------------------------------------------------------- | ------ |
| e    | Action< [SPhysicsHit](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sphysicshit.md) > | –      |
| e    | Closure                                                                                              | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnCollisionExit = function(SPhysicsHit)
 Space.Log("Collision Exit")
end

this.OnCollisionExit(OnCollisionExit)

```

**Lua**

```lua
--this script will make this object destroy itself when an object 
--that collided with it exits the collission
--(Example: landmine)
--[Make sure you add a rigibody to this object (read above about "collisions")


thisGameObject = Space.Host.ExecutingObject


OnCollisionExit = function(SPhysicsHit)
 thisGameObject.Destroy()
end

thisGameObject.OnCollisionExit(OnCollisionExit)

```

### OnParticleCollision

void OnParticleCollision(Action< SGameObject > e)

void OnParticleCollision(Closure e)

OnParticleCollision is called when a particle hits a Collider.

This can be used to apply damage to a GameObject when hit by particles.

This message is sent to scripts attached to Particle Systems and to the Collider that was hit.

When OnParticleCollision is invoked from a script attached to a GameObject with a Collider, the GameObject parameter represents the ParticleSystem. The Collider receives at most one message per Particle System that collided with it in any given frame even when the Particle System struck the Collider with multiple particles in the current frame.

When OnParticleCollision is invoked from a script attached to a ParticleSystem, the GameObject parameter represents a GameObject with an attached Collider struck by the ParticleSystem. The ParticleSystem receives at most one message per Collider that is struck.

Messages are only sent if you enable Send Collision Messages in the Inspector of the Particle System Collision module.

The OnParticleCollision can be a co-routine. Simply use the yield statement in the function.

参数

| 名称 | 类型                  | 默认值 |
| ---- | --------------------- | ------ |
| e    | Action< SGameObject > | –      |
| e    | Closure               | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnParticleCollision = function(GameObject)
 Space.Log("Particle Collision")
end

this.OnParticleCollision(OnParticleCollision)

```

### OnParticleTrigger

void OnParticleTrigger(Closure e)

Binds a new event handler for the OnParticleTrigger event.

OnParticleTrigger event is called when any particles in a Particle System meet the conditions in the trigger module.

This can be used to kill or modify particles that are inside or outside a collision volume.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnParticleTrigger = function(GameObject)
 Space.Log("Particle Trigger Event")
end

this.OnParticleTrigger(OnParticleTrigger)

```

### OnUpdate

void OnUpdate(Closure e)

Binds a event to the OnUpdate() event.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function F()
Space.Log("bound")
end
Space.Host.ExecutingObject.OnUpdate(F)

```

**Lua**

```lua
--this script will make this object move forward each frame
thisObject = Space.Host.ExecutingObject

OnUpdate = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (thisObject.Forward * 0.01 * Space.DeltaTime)
--we multipy by Space.DeltaTime so that it behaves the same for all players
--even though they have different FPS (frames per second)
end


thisObject.OnUpdate(OnUpdate)

```

### OnMouseDown

void OnMouseDown(Closure e)

Binds a event to the OnMouseDown() event.

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function F()
Space.Log("bound")
end
Space.Host.ExecutingObject.OnMouseDown(F)

```

### OnApplicationQuit

void OnApplicationQuit(Closure e)

Binds a new event handler for the On Application Quit event

参数

| 名称 | 类型    | 默认值 |
| ---- | ------- | ------ |
| e    | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
this = Space.Host.ExecutingObject

OnApplicationQuit = function()
 Space.Log("Application Quit")
end

this.OnApplicationQuit(OnApplicationQuit)

```

### CompareTag

bool CompareTag(string tag)

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| tag  | string | –      |

返回值

`bool`

示例

**Lua**

```lua
isSame = Space.Host.ExecutingObject.CompareTag('tagname')

```

### SetParent

void SetParent(SGameObject other, bool worldPositionStays = true)

Make this GameObject the child of GameObject 'other'

参数

| 名称               | 类型        | 默认值 |
| ------------------ | ----------- | ------ |
| other              | SGameObject | –      |
| worldPositionStays | bool        | true   |

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.SetParent(otherObjectReference,true)

```

**Lua**

```lua
--this script will set your avatar's "right hand" as parent of this object
--this way this object will be a child of your right hand and therefore move with it
--(Example: clicking on a gun to equip it)


thisGameObject = Space.Host.ExecutingObject

OnClick = function()

RightHand = Space.Scene.PlayerAvatar.FindBone("RightHand")
thisGameObject.SetParent(RightHand)
thisGameObject.LocalPosition = Vector.New(0,0,0) -- resetting position to match hand

end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip="Click to Equip "
thisGameObject.Clickable.OnClick(OnClick)

```

### Find

SGameObject Find(string name)

Find and return a reference to GameObject with name 'name'

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SGameObject`

示例

**Lua**

```lua
FoundObject = Space.Host.ExecutingObject.Find("GameObject Name")

```

### FindInChildren

SGameObject FindInChildren(string name)

Find and return a reference to GameObject with name 'name' including children

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SGameObject`

示例

**Lua**

```lua
FoundObjectInChildren = Space.Host.ExecutingObject.FindInChildren("GameObject Name")

```

### Destroy

void Destroy()

Schedules this object for deletion at the end of the frame

返回值

`void`

示例

**Lua**

```lua
Space.Host.ExecutingObject.Destroy()

```

### GetComponent

SComponent GetComponent(string name)

危险

Depreciated

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| name | string | –      |

返回值

`SComponent`

## 属性

### Owner

long Owner {get; }

Returns the GameObject's Owner

示例

**Lua**

```lua
Owner = Space.Host.ExecutingObject.Owner

```

### LocalID

int LocalID {get; }

Returns the GameObject's Local ID

示例

**Lua**

```lua
LocalID = Space.Host.ExecutingObject.LocalID

```

### InventoryID

int InventoryID {get; }

Return's the GameObject's InventoryID

示例

**Lua**

```lua
InventoryID = Space.Host.ExecutingObject.InventoryID

```

### HasStableID

bool HasStableID {get; }

Returns true if GameObject has Stable ID

示例

**Lua**

```lua
HasStableID = Space.Host.ExecutingObject.HasStableID

```

### GlobalID

string? GlobalID {get; }

Returns the global ID of the GameObject

示例

**Lua**

```lua
GlobalID = Space.Host.ExecutingObject.GlobalID

```

### Exists

bool Exists {get; }

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

示例

**Lua**

```lua
doesExist = Space.Host.ExecutingObject.Exists

```

### HingeJoint

[SHingeJoint](/docs/zh-Hans/scripting/client-scripting-api-reference/components/shingejoint.md) HingeJoint {get; }

Returns a HingeJoint component attached to this object, or nil if none exist

示例

**Lua**

```lua
HingeJoint = Space.Host.ExecutingObject.HingeJoint

```

### Light

[SLight](/docs/zh-Hans/scripting/client-scripting-api-reference/components/slight.md) Light {get; }

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

示例

**Lua**

```lua
newLightComponent = Space.Host.ExecutingObject.Light

```

### ReflectionProbe

[SReflectionProbe](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sreflectionprobe.md) ReflectionProbe {get; }

Returns a ReflectionProbe component attached to this object, or nil if none exist

示例

**Lua**

```lua
ReflectionProbe = Space.Host.ExecutingObject.ReflectionProbe

```

### LightInChild

[SLight](/docs/zh-Hans/scripting/client-scripting-api-reference/components/slight.md) LightInChild {get; }

Returns a Light component attached to this object or its children, or nil if none exist

示例

**Lua**

```lua
LightInChild = Space.Host.ExecutingObject.LightInChild

```

### LightInParent

[SLight](/docs/zh-Hans/scripting/client-scripting-api-reference/components/slight.md) LightInParent {get; }

Returns a Light component attached to this object or it's parent, or nil if none exist

示例

**Lua**

```lua
LightInParent = Space.Host.ExecutingObject.LightInParent

```

### Animator

[SAnimator](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sanimator.md) Animator {get; }

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

示例

**Lua**

```lua
animatorComponent = Space.Host.ExecutingObject.Animator

```

### Animation

[SAnimation](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sanimation.md) Animation {get; }

Returns an Animation component attached to this object, or nil if none exist Animation is a legacy component and should not be confused with Animator

示例

**Lua**

```lua
Animation = Space.Host.ExecutingObject.Animation

```

### CanvasGroup

[SCanvasGroup](/docs/zh-Hans/scripting/client-scripting-api-reference/components/scanvasgroup.md) CanvasGroup {get; }

Returns Canvas Group component attached to this object, or nil if none exist

示例

**Lua**

```lua
CanvasGroup = Space.Host.ExecutingObject.CanvasGroup

```

### Audio

[SAudioSource](/docs/zh-Hans/scripting/client-scripting-api-reference/components/saudiosource.md) Audio {get; }

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

示例

**Lua**

```lua
newAudioComponent = Space.Host.ExecutingObject.Audio

```

### Floor

[SRoomFloor](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sroomfloor.md) Floor {get; }

Returns a RoomFloor component attached to this object, or nil if none exist

示例

**Lua**

```lua
Floor = Space.Host.ExecutingObject.Floor

```

### VoiceZone

[SVoiceZone](/docs/zh-Hans/scripting/client-scripting-api-reference/components/svoicezone.md) VoiceZone {get; }

Returns a VoiceZone component attached to this object, or nil if none exist

示例

**Lua**

```lua
VoiceZone = Space.Host.ExecutingObject.VoiceZone

```

### Browser

[SBrowserSurface](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sbrowsersurface.md) Browser {get; }

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

示例

**Lua**

```lua
newBrowserComponent = Space.Host.ExecutingObject.Browser

```

### Director

[SPlayableDirector](/docs/zh-Hans/scripting/client-scripting-api-reference/components/splayabledirector.md) Director {get; }

Returns a PlayableDirector component attached to this object, or nil if none exist

示例

**Lua**

```lua
Director = Space.Host.ExecutingObject.Director

```

### Renderer

[SRenderer](/docs/zh-Hans/scripting/client-scripting-api-reference/components/srenderer.md) Renderer {get; }

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

示例

**Lua**

```lua
renderer = Space.Host.ExecutingObject.Renderer

```

### Vehicle

[SModularVehicle](/docs/zh-Hans/scripting/client-scripting-api-reference/components/smodularvehicle.md) Vehicle {get; }

Returns a Modular Vehicle component attached to this object, or nil if none exist

示例

**Lua**

```lua
Vehicle = Space.Host.ExecutingObject.Vehicle

```

### PostProcessVolume

[SPostProcessVolume](/docs/zh-Hans/scripting/client-scripting-api-reference/components/spostprocessvolume.md) PostProcessVolume {get; }

Returns a Post Process Volume component attached to this object, or nil if none exist

示例

**Lua**

```lua
PostProcessVolume = Space.Host.ExecutingObject.PostProcessVolume

```

### Archimatix

SAXModel Archimatix {get; }

Returns a Archimatix Model ("AXModel" component) - or Nil if nothing exists

示例

**Lua**

```lua
Archimatix = Space.Host.ExecutingObject.Archimatix

```

### Clickable

[SClickable](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sclickable.md) Clickable {get; }

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

示例

**Lua**

```lua
clickableComponent = Space.Host.ExecutingObject.Clickable

```

### EmbeddedVideo

[SEmbeddedVideo](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sembeddedvideo.md) EmbeddedVideo {get; }

Returns an Embedded Video component attached to this object, or nil if none exist (may not work within editor)

示例

**Lua**

```lua
EmbeddedVideo = Space.Host.ExecutingObject.EmbeddedVideo

```

### Avatar

[SAvatar](/docs/zh-Hans/scripting/client-scripting-api-reference/types/savatar.md) Avatar {get; }

A reference to an Avatar component on the GameObject.

示例

**Lua**

```lua
Avatar = Space.Host.ExecutingObject.Avatar

```

### AvatarAppearance

[SAvatarAppearance](/docs/zh-Hans/scripting/client-scripting-api-reference/types/savatarappearance.md) AvatarAppearance {get; }

Returns a AvatarAppearance component attached to this object, or nil if none exist

示例

**Lua**

```lua
AvatarAppearance = Space.Host.ExecutingObject.AvatarAppearance

```

### Script

[SScriptingRuntime](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingruntime.md) Script {get; }

Returns a Scripting Runtime component attached to this object, or nil if none exist

示例

**Lua**

```lua
Script = Space.Host.ExecutingObject.Script

```

### StateMachine

[SStateMachine](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sstatemachine.md) StateMachine {get; }

Returns a State Machine component attached to this object, or nil if none exist

示例

**Lua**

```lua
StateMachine = Space.Host.ExecutingObject.StateMachine

```

### Networking

[SNetworking](/docs/zh-Hans/scripting/client-scripting-api-reference/components/snetworking.md) Networking {get; }

Returns a Simple Networking component attached to this object, or nil if none exists

示例

**Lua**

```lua
SimpleNetworking = Space.Host.ExecutingObject.Networking

```

### Events

[SScriptingEvents](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingevents.md) Events {get; }

示例

**Lua**

```lua
eventsComponent = Space.Host.ExecutingObject.Events

```

### Resources

[SScriptingResources](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingresources.md) Resources {get; }

示例

**Lua**

```lua
resourcesComponent = Space.Host.ExecutingObject.Resources

```

### Data

[SScriptingData](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscriptingdata.md) Data {get; }

Returns a Scripting Data component attached to this object, or nil if none exist

示例

**Lua**

```lua
Data = Space.Host.ExecutingObject.Data

```

### Rigidbody

[SRigidbody](/docs/zh-Hans/scripting/client-scripting-api-reference/components/srigidbody.md) Rigidbody {get; }

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

示例

**Lua**

```lua
rigidbodyComponent = Space.Host.ExecutingObject.Rigidbody

```

### Collider

[SCollider](/docs/zh-Hans/scripting/client-scripting-api-reference/components/scollider.md) Collider {get; }

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

示例

**Lua**

```lua
colliderComponent =  Space.Host.ExecutingObject.Collider

```

### BoxCollider

[SBoxCollider](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sboxcollider.md) BoxCollider {get; }

Returns a Box Collider component attached to this object, or nil if none exist

示例

**Lua**

```lua
BoxCollider = Space.Host.ExecutingObject.BoxCollider

```

### SphereCollider

[SSphereCollider](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sspherecollider.md) SphereCollider {get; }

Returns a Sphere Collider component attached to this object, or nil if none exist

示例

**Lua**

```lua
SphereCollider = Space.Host.ExecutingObject.SphereCollider

```

### CapsuleCollider

[SCapsuleCollider](/docs/zh-Hans/scripting/client-scripting-api-reference/components/scapsulecollider.md) CapsuleCollider {get; }

Returns a Capsule Collider component attached to this object, or nil if none exist

示例

**Lua**

```lua
CapsuleCollider = Space.Host.ExecutingObject.CapsuleCollider

```

### WheelCollider

[SWheelCollider](#) WheelCollider {get; }

Returns a WheelCollider component attached to this object, or nil if none exist

示例

**Lua**

```lua
WheelCollider = Space.Host.ExecutingObject.WheelCollider

```

### CharacterController

[SCharacterController](/docs/zh-Hans/scripting/client-scripting-api-reference/components/scharactercontroller.md) CharacterController {get; }

Returns a Character Controller component attached to this object, or nil if none exist

示例

**Lua**

```lua
CharacterController = Space.Host.ExecutingObject.CharacterController

```

### AudioReactive

[SAudioReactiveBase](/docs/zh-Hans/scripting/client-scripting-api-reference/components/saudioreactivebase.md) AudioReactive {get; }

Returns the first Audio Reactive component attached to this object, or nil if none exist

示例

**Lua**

```lua
AudioReactive = Space.Host.ExecutingObject.AudioReactive

```

### AttachmentHelper

SAttachmentHelper AttachmentHelper {get; }

Returns the first Attachment Helper component attached to this object, or nil if none exist

示例

**Lua**

```lua
AttachmentHelper = Space.Host.ExecutingObject.AttachmentHelper

```

### AudioReactiveAnimation

[SAudioReactiveAnimation](/docs/zh-Hans/scripting/client-scripting-api-reference/components/saudioreactiveanimation.md) AudioReactiveAnimation {get; }

Returns the first Audio Reactive Animation component attached to this object, or nil if none exist

示例

**Lua**

```lua
AudioReactiveAnimation = Space.Host.ExecutingObject.AudioReactiveAnimation

```

### AudioReactiveLight

[SAudioReactiveLight](/docs/zh-Hans/scripting/client-scripting-api-reference/components/saudioreactivelight.md) AudioReactiveLight {get; }

Returns the first Audio Reactive Light component attached to this object, or nil if none exist

示例

**Lua**

```lua
AudioReactiveLight = Space.Host.ExecutingObject.AudioReactiveLight

```

### AudioReactiveParticleSystem

[SAudioReactiveParticleSystem](/docs/zh-Hans/scripting/client-scripting-api-reference/components/saudioreactiveparticlesystem.md) AudioReactiveParticleSystem {get; }

Returns the first Audio Reactive Particle System component attached to this object, or nil if none exist

示例

**Lua**

```lua
AudioReactiveParticleSystem = Space.Host.ExecutingObject.AudioReactiveParticleSystem

```

### AudioReactiveMaterial

[SAudioReactiveMaterial](/docs/zh-Hans/scripting/client-scripting-api-reference/components/saudioreactivelight.md) AudioReactiveMaterial {get; }

Returns the first Audio Reactive Material component attached to this object, or nil if none exist

示例

**Lua**

```lua
AudioReactiveMaterial = Space.Host.ExecutingObject.AudioReactiveMaterial

```

### AudioReactiveTransform

[SAudioReactiveTransform](/docs/zh-Hans/scripting/client-scripting-api-reference/components/saudioreactivetransform.md) AudioReactiveTransform {get; }

Returns the first Audio Reactive Transform component attached to this object, or nil if none exist

示例

**Lua**

```lua
AudioReactiveTransform = Space.Host.ExecutingObject.AudioReactiveTransform

```

### TrailRenderer

[STrailRenderer](/docs/zh-Hans/scripting/client-scripting-api-reference/components/strailrenderer.md) TrailRenderer {get; }

Returns a Trail Renderer component attached to this object, or nil if none exist

示例

**Lua**

```lua
TrailRenderer = Space.Host.ExecutingObject.TrailRenderer

```

### LineRenderer

[SLineRenderer](/docs/zh-Hans/scripting/client-scripting-api-reference/components/slinerenderer.md) LineRenderer {get; }

Returns a Line Renderer component attached to this object, or nil if none exist

示例

**Lua**

```lua
LineRenderer = Space.Host.ExecutingObject.LineRenderer

```

### UILayout

[SUILayout](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suilayout.md) UILayout {get; }

Returns a Renderer component attached to this object, or nil if none exist

示例

**Lua**

```lua
UILayout = Space.Host.ExecutingObject.UILayout

```

### UIToggle

[SUIToggle](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suitoggle.md) UIToggle {get; }

Returns a Unity uGUI Toggle component attached to this object, or nil if none exist

示例

**Lua**

```lua
UIToggle = Space.Host.ExecutingObject.UIToggle

```

### UIDropdown

[SUIDropdown](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suidropdown.md) UIDropdown {get; }

Returns a Unity uGUI Dropdown component attached to this object, or nil if none exist

示例

**Lua**

```lua
UIDropdown = Space.Host.ExecutingObject.UIDropdown

```

### UIButton

[SUIButton](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suibutton.md) UIButton {get; }

Returns a Unity uGUI Dropdown component attached to this object, or nil if none exist

示例

**Lua**

```lua
UIButton = Space.Host.ExecutingObject.UIButton

```

### UIText

[SUIText](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suitext.md) UIText {get; }

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

示例

**Lua**

```lua
uitext = Space.Host.ExecutingObject.UIText 

```

### UISlider

[SUISlider](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suislider.md) UISlider {get; }

Returns a Unity uGUI Slider component attached to this object, or nil if none exist

示例

**Lua**

```lua
UISlider = Space.Host.ExecutingObject.UISlider

```

### UIScrollbar

[SUIScrollbar](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suiscrollbar.md) UIScrollbar {get; }

Returns a Unity uGUI Scrollbar component attached to this object, or nil if none exist

示例

**Lua**

```lua
UIScrollbar = Space.Host.ExecutingObject.UIScrollbar

```

### UICanvas

[SUICanvas](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suicanvas.md) UICanvas {get; }

Returns a Unity uGUI Canvas component attached to this object, or nil if none exist

示例

**Lua**

```lua
UICanvas = Space.Host.ExecutingObject.UICanvas

```

### UIImage

[SUIImage](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suiimage.md) UIImage {get; }

Returns a Unity uGUI Image component attached to this object, or nil if none exist

示例

**Lua**

```lua
UIImage = Space.Host.ExecutingObject.UIImage

```

### UIRawImage

[SUIRawImage](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suirawimage.md) UIRawImage {get; }

Returns a Unity uGUI Text component attached to this object, or nil if none exist

示例

**Lua**

```lua
UIRawImage = Space.Host.ExecutingObject.UIRawImage

```

### UIInputField

[SUIInputField](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suiinputfield.md) UIInputField {get; }

Returns a Unity uGUI Text component attached to this object, or nil if none exist

示例

**Lua**

```lua
UIInputField = Space.Host.ExecutingObject.UIInputField

```

### UIToolTipHint

[SUIToolTipHint](/docs/zh-Hans/scripting/client-scripting-api-reference/components/suitooltiphint.md) UIToolTipHint {get; }

示例

**Lua**

```lua
tooltipHint = Space.Host.ExecutingObject.UIToolTipHint

```

### Camera

[SCamera](/docs/zh-Hans/scripting/client-scripting-api-reference/components/scamera.md) Camera {get; }

示例

**Lua**

```lua
camera = Space.Host.ExecutingObject.Camera

```

### VirtualCamera

[SVirtualCamera](/docs/zh-Hans/scripting/client-scripting-api-reference/components/svirtualcamera.md) VirtualCamera {get; }

Returns a VirtualCamera component attached to this object, or nil if none exists

示例

**Lua**

```lua
VirtualCamera = Space.Host.ExecutingObject.VirtualCamera

```

### Cloth

[SCloth](/docs/zh-Hans/scripting/client-scripting-api-reference/components/scloth.md) Cloth {get; }

Returns a Cloth component attached to this object, or nil if none exists

示例

**Lua**

```lua
Cloth = Space.Host.ExecutingObject.Cloth

```

### MeshRenderer

[SMeshRenderer](/docs/zh-Hans/scripting/client-scripting-api-reference/components/smeshrenderer.md) MeshRenderer {get; }

Returns a MeshRenderer component attached to this object, or nil if none exists

示例

**Lua**

```lua
MeshRenderer = Space.Host.ExecutingObject.MeshRenderer

```

### Furniture

[SFurniture](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sfurniture.md) Furniture {get; }

Returns a Furniture component attached to this object, or nil if none exists

示例

**Lua**

```lua
Furniture = Space.Host.ExecutingObject.Furniture

```

### NavMeshAgent

[SNavMeshAgent](/docs/zh-Hans/scripting/client-scripting-api-reference/components/snavmeshagent.md) NavMeshAgent {get; }

Adds a NavMeshAgent component to the object.

示例

**Lua**

```lua
navMeshAgent = Space.Host.ExecutingObject.AddNavMeshAgent()

```

### NavMeshObstacle

[SNavMeshObstacle](/docs/zh-Hans/scripting/client-scripting-api-reference/components/snavmeshobstacle.md) NavMeshObstacle {get; }

Returns a NavMeshObstacle component attached to this object, or nil if none exists

示例

**Lua**

```lua
NavMeshObstacle = Space.Host.ExecutingObject.NavMeshObstacle

```

### ParticleSystem

[SParticleSystem](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sparticlesystem.md) ParticleSystem {get; }

Returns a ParticleSystem component attached to this object, or nil if none exists

示例

**Lua**

```lua
ParticleSystem = Space.Host.ExecutingObject.ParticleSystem

```

### RectTransform

[SRectTransform](/docs/zh-Hans/scripting/client-scripting-api-reference/components/srecttransform.md) RectTransform {get; }

Returns a RectTransform component attached to this object, or nil if none exists

示例

**Lua**

```lua
RectTransform = Space.Host.ExecutingObject.RectTransform

```

### Seat

[SSeat](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sseat.md) Seat {get; }

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

示例

**Lua**

```lua
seatComponent = Space.Host.ExecutingObject.AddSeat()

```

### SkinnedMeshRenderer

[SSkinnedMeshRenderer](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sskinnedmeshrenderer.md) SkinnedMeshRenderer {get; }

Returns a SkinnedMeshRenderer component attached to this object, or nil if none exists

示例

**Lua**

```lua
SkinnedMeshRenderer = Space.Host.ExecutingObject.SkinnedMeshRenderer

```

### Radio

[SSceneBackgroundMusic](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sscenebackgroundmusic.md) Radio {get; }

Returns a SceneBackgroundMusic component attached to this object, or nil if none exists

示例

**Lua**

```lua
Radio = Space.Host.ExecutingObject.Radio

```

### Terrain

[STerrain](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sterrain.md) Terrain {get; }

Returns a Terrain component attached to this object, or nil if none exists

示例

**Lua**

```lua
Terrain = Space.Host.ExecutingObject.Terrain

```

### AnalyticsEvent

SAnalyticsEvent AnalyticsEvent {get; }

示例

**Lua**

```lua
analyticsEvent = Space.Host.ExecutingObject.AnalyticsEvent

```

### GraphicRaycaster

[SGraphicRaycaster](/docs/zh-Hans/scripting/client-scripting-api-reference/components/sgraphicraycaster.md) GraphicRaycaster {get; }

示例

**Lua**

```lua
graphicRaycaster = Space.Host.ExecutingObject.GraphicRaycaster

```

### ContentSizeFitter

SContentSizeFitter ContentSizeFitter {get; }

示例

**Lua**

```lua
contentSzeFitter = Space.Host.ExecutingObject.ContentSizeFitter

```

### Active

bool Active {get; set; }

Is this object Active in the scene

示例

**Lua**

```lua
Space.Host.ExecutingObject.Active = false

```

**Lua**

```lua
--the below script will make this object become inactive
--after being being clicked
--(Example: picking up fruits)

thisGameObject = Space.Host.ExecutingObject


OnClick = function()
thisGameObject.Active = false
end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip="Pick me!"
thisGameObject.Clickable.OnClick(OnClick)

```

### ActiveSelf

bool ActiveSelf {get; set; }

Returns true if GameObject is Active (even if it's parent is not active)

示例

**Lua**

```lua
 Space.Host.ExecutingObject.ActiveSelf = false

```

### Layer

int Layer {get; set; }

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

示例

**Lua**

```lua
Space.Host.ExecutingObject.Layer = 21

```

### Tag

string Tag {get; }

Gets this objects Tag

示例

**Lua**

```lua
objectTag = Space.Host.ExecutingObject.Tag

```

### Name

string Name {get; set; }

Gets/sets the name of this object

示例

**Lua**

```lua
Space.Host.ExecutingObject.Name = 'Hello World!'

```

### Moniker

string? Moniker {get; set; }

示例

**Lua**

```lua
Space.Host.ExecutingObject.Moniker = 'New  Moniker'

```

### Parent

[SGameObject](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sgameobject.md) Parent {get; set; }

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

示例

**Lua**

```lua
Space.Host.ExecutingObject.Parent = Space.Host.GetReference("TheOtherObject")

```

### Root

[SGameObject](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sgameobject.md) Root {get; }

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

示例

**Lua**

```lua
objectRoot = Space.Host.ExecutingObject.Root

```

### Children

[SGameObject](/docs/zh-Hans/scripting/client-scripting-api-reference/types/sgameobject.md)\[] Children {get; }

Returns the list of direct children of this object.

示例

**Lua**

```lua
tableChildren = Space.Host.ExecutingObject.Children

```

### WorldPosition

[SVector](/docs/zh-Hans/scripting/client-scripting-api-reference/types/svector.md) WorldPosition {get; set; }

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

示例

**Lua**

```lua
Space.Host.ExecutingObject.WorldPosition = Vector.New(1,1,1)

```

### LocalPosition

[SVector](/docs/zh-Hans/scripting/client-scripting-api-reference/types/svector.md) LocalPosition {get; set; }

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

示例

**Lua**

```lua
Space.Host.ExecutingObject.LocalPosition = Vector.New(1,1,1)

```

### WorldRotation

[SQuaternion](/docs/zh-Hans/scripting/client-scripting-api-reference/types/squaternion.md) WorldRotation {get; set; }

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

示例

**Lua**

```lua
Space.Host.ExecutingObject.WorldRotation = Quaternion.Euler(0,180,0)

```

### LocalRotation

[SQuaternion](/docs/zh-Hans/scripting/client-scripting-api-reference/types/squaternion.md) LocalRotation {get; set; }

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

示例

**Lua**

```lua
Space.Host.ExecutingObject.LocalRotation = Quaternion.Euler(0,180,0)

```

### LocalScale

[SVector](/docs/zh-Hans/scripting/client-scripting-api-reference/types/svector.md) LocalScale {get; set; }

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

示例

**Lua**

```lua
Space.Host.ExecutingObject.LocalScale = Vector.New(2,2,2)

```

### WorldScale

[SVector](/docs/zh-Hans/scripting/client-scripting-api-reference/types/svector.md) WorldScale {get; }

Gets the current scale of this object relative to the scene

示例

**Lua**

```lua
worldScale = Space.Host.ExecutingObject.WorldScale 

```

### Forward

[SVector](/docs/zh-Hans/scripting/client-scripting-api-reference/types/svector.md) Forward {get; }

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

示例

**Lua**

```lua
vectorForward = Space.Host.ExecutingObject.Forward

```

### Up

[SVector](/docs/zh-Hans/scripting/client-scripting-api-reference/types/svector.md) Up {get; }

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

示例

**Lua**

```lua
vectorUp = Space.Host.ExecutingObject.Up

```

### Right

[SVector](/docs/zh-Hans/scripting/client-scripting-api-reference/types/svector.md) Right {get; }

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

示例

**Lua**

```lua
vectorRight = Space.Host.ExecutingObject.Right

```

### EventCalendar

[SEventCalendar](/docs/zh-Hans/scripting/client-scripting-api-reference/components/seventcalendar.md) EventCalendar {get; }

Returns an EventCalendar component attached to this object, or nil if none exists

示例

**Lua**

```lua
EventCalendar = Space.Host.ExecutingObject.EventCalendar

```
