The GetComponents<T>
method retrieves all components of type T
attached to the current GameObject
. This method can optionally include components that are currently disabled.
The GetComponents<T>
method retrieves all components of type T
attached to the current GameObject
. This method can optionally include components that are currently disabled.
To use the GetComponents<T>
method, specify the type of component you want to retrieve as the generic type parameter T
. Pass a boolean parameter includeDisabled
to indicate whether to include disabled components in the result.
// Example of using GetComponents to retrieve all components of a specific type public void ExampleUsage() { // Assume this script is attached to a GameObject var components = GetComponents<MyComponentType>(includeDisabled: true); foreach (var component in components) { // Perform operations with each component component.DoSomething(); } }