Skip to content

Component

extends EngineObject

The base class for all components attached to game objects.

You can obtain a Component object by using the following method:

typescript
let go = new GameObject();
// Add a BoxCollider component to the game object
let com = go.AddComponent<BoxCollider>(BoxCollider);

成员变量

Component.instanceID : number
(Read Only) The instance ID of the object.
Component.transform : Transform
(Read Only) The transform component attached to this game object.
Component.gameObject : GameObject
(Read Only) The game object to which the current component is attached.
Component.enable : boolean
The enabled state of the component.
Component.allowEnable : boolean
(Read Only) Whether the component is enabled.

成员方法

Component.toString ( ) : string
Returns the type alias (component name) of the component.
Component.OnTriggerEnter ( collider : Collider ) : void
Component.OnTriggerStay ( collider : Collider ) : void
Component.OnTriggerExit ( collider : Collider ) : void
Component.OnCollisionEnter ( collision : Collision ) : void
在碰撞器与另一个碰撞器发生碰撞时调用此方法。
Component.OnCollisionStay ( collision : Collision ) : void
在两个碰撞器之间的碰撞持续期间调用此方法。
Component.OnCollisionExit ( collision : Collision ) : void
在两个碰撞器之间的碰撞结束时调用此方法。
Component.OnCollisionExit ( collision : ControllerColliderHit ) : void
在两个碰撞器之间的碰撞结束时调用此方法。
Component.OnDestroy ( ) : void
当组件被销毁时调用此方法。
Component.OnDisable ( ) : void
当组件被禁用时调用该方法。
Component.OnEnable ( ) : void
当组件被启用时调用该方法。
Component.OnDrawGizmos ( ) : void
绘制Gizmos时调用此方法。
Component.OnDrawGizmosSelected ( ) : void
在选中游戏对象并绘制Gizmos时调用此方法,允许你在编辑器中以选中状态下绘制特定的Gizmos。
Component.OnUpdate ( ) : void
如果注册此方法,那么在每一帧的开始时都会执行此方法。
Component.OnLateUpdate ( ) : void
Component.OnForceUpdate ( ) : void
如果注册此方法,会在固定的时间间隔内被调用,而不是每一帧都被调用。
Component.OnGUI ( ) : void
Component.OnInvoke ( ) : void
Component.OnStart ( ) : void
对象加载完成,第一次执行OnUpdate方法前执行此方法。
Component.OnPostRender ( ) : void
Component.OnPreRender ( ) : void
Component.OnPreCull ( ) : void
Component.OnRenderImage ( src : RenderTexture , dst : RenderTexture ) : void
Component.OnRenderObject ( ) : void