IEnumerable<T> GetComponents( bool includeDisabled )

book_4_sparkGenerated
code_blocksInput

Description

The GetComponents<T> method retrieves all components of type T attached to the GameObject. This method can optionally include components that are currently disabled.

Usage

Use this method when you need to access multiple components of a specific type on a GameObject. You can specify whether to include disabled components by setting the includeDisabled parameter to true or false.

Example

// Example of using GetComponents to retrieve all components of a specific type
var gameObject = new GameObject();

// Retrieve all components of type MyComponent, including disabled ones
var components = gameObject.GetComponents<MyComponent>(true);

foreach (var component in components)
{
    // Perform operations with each component
    component.DoSomething();
}