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.
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.
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 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(); } }