ComponentList Components { get; set; }

robot_2Generated
code_blocksInput

Description

Access components on this GameObject.

Usage

The Components property provides access to the list of components attached to the GameObject. This allows you to iterate over, add, or remove components dynamically at runtime.

Example

// Example of accessing components on a GameObject
GameObject myObject = new GameObject();

// Access the components list
ComponentList components = myObject.Components;

// Iterate over components
foreach (var component in components)
{
    // Do something with each component
    Console.WriteLine(component.GetType().Name);
}

// Add a new component
myObject.Components.Add(new MyCustomComponent());

// Remove a component
var componentToRemove = myObject.Components.FirstOrDefault(c => c is MyCustomComponent);
if (componentToRemove != null)
{
    myObject.Components.Remove(componentToRemove);
}