Skip to content

format

typescript
GameObject.GetComponents(type)

class: GameObject

description

Returns all components of type type in the GameObject.

parameter

param_nametypedescription
typeComponentThe type of component.

reture

typedescription
T|nullReturns an array containing the components of the specified type. If no components of the specified type are found, returns null.

code example

typescript
let go = new GameObject();
// Get the BoxCollider component in the GameObject or any of its children
let box = go.GetComponents(BoxCollider);
if(box){
    Debug.Log(box);
}else{
    Debug.Log("Component not found");
}