format
typescript
GameObject.GetComponents(type)class: GameObject
description
Returns all components of type type in the GameObject.
parameter
| param_name | type | description |
|---|---|---|
| type | Component | The type of component. |
reture
| type | description |
|---|---|
T|null | Returns 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");
}