Component
Type | Name | Interface Description |
---|---|---|
Variables | enabled: boolean | • Function: Indicates whether the component is enabled. If the component is disabled, it may not be updated or rendered. |
Functions | getSceneObject(): SceneObject | • Function: Get the SceneObject object to which this component belongs. • Return Value: Returns a SceneObject object that contains the component. |
Functions | isInheritedEnabled(): boolean | • Function: Check whether the component is enabled and whether its parent object is also enabled. • Return value: Returns true if both the component and its parent object are enabled; otherwise, returns false. |
Examples
enabled: boolean
meshrenderer.enabled = false
getSceneObject() : SceneObject
let sceneObject = component.getSceneObject();
isInheritedEnabled(): boolean
let inheritedEnabled = component.isInheritedEnabled();
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
let child = this.getSceneObject().getChild('Cube');
let meshRenderer = child?.getComponent('MeshRenderer');
if(meshRenderer){
meshRenderer.enabled = false;
console.log("meshRenderer enabled:", meshRenderer.isInheritedEnabled());
console.log("sceneObject enabled:", meshRenderer.getSceneObject().enabled);
}
}
}
}
