Description
The GetAllObjects
method retrieves all GameObject
instances within the current context, filtered by their enabled state. This method is useful for iterating over all game objects in a scene or a specific context, allowing you to perform operations on them based on whether they are enabled or not.
Usage
To use the GetAllObjects
method, call it on an instance of GameObject
. Pass a boolean parameter to specify whether you want to include only enabled objects or all objects regardless of their enabled state.
Parameters:
enabled
(Boolean): If set to true
, only enabled GameObject
instances will be returned. If false
, all objects will be returned regardless of their enabled state.
Example
// Example usage of GetAllObjects method
// Assume 'gameObject' is an instance of GameObject
IEnumerable<GameObject> enabledObjects = gameObject.GetAllObjects(true);
foreach (var obj in enabledObjects)
{
// Perform operations on each enabled GameObject
obj.DoSomething();
}
// To get all objects regardless of their enabled state
IEnumerable<GameObject> allObjects = gameObject.GetAllObjects(false);
foreach (var obj in allObjects)
{
// Perform operations on each GameObject
obj.DoSomethingElse();
}