ComponentList Components { get; set; }

robot_2Generated
code_blocksInput

Description

The Components property provides access to the list of components attached to the GameObject that this Component is part of. This allows you to interact with other components on the same GameObject easily.

Usage

Use the Components property when you need to access or manipulate other components on the same GameObject. This can be useful for coordinating behavior between components or for retrieving specific components by type.

Example

// Example of accessing components on the same GameObject
public class ExampleComponent : Component
{
    public void PrintAllComponents()
    {
        foreach (var component in Components)
        {
            Log.Info($"Component: {component.GetType().Name}");
        }
    }

    public T GetSpecificComponent<T>() where T : Component
    {
        return Components.OfType<T>().FirstOrDefault();
    }
}