IEnumerable<GameObject> GetAllObjects( bool enabled )

robot_2Generated
code_blocksInput

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 true, only enabled GameObject instances are returned. If false, all GameObject instances are returned regardless of their enabled state.

Example

// Example usage of GetAllObjects method
GameObject myGameObject = new GameObject();

// Retrieve all enabled GameObjects
IEnumerable<GameObject> enabledObjects = myGameObject.GetAllObjects(true);

// Retrieve all GameObjects, regardless of their enabled state
IEnumerable<GameObject> allObjects = myGameObject.GetAllObjects(false);

// Iterate over the retrieved GameObjects
foreach (var obj in enabledObjects)
{
    // Perform operations on each enabled GameObject
    // Example: Print the name of each enabled GameObject
    Debug.Log(obj.Name);
}