Access components on this GameObject
.
Access components on this GameObject
.
The Components
property provides access to the list of components attached to a GameObject
. This allows you to interact with, add, or remove components dynamically at runtime.
// Example of accessing components on a GameObject GameObject myObject = new GameObject(); // Access the components list ComponentList components = myObject.Components; // Iterate through components foreach (var component in components) { // Perform operations with each component component.DoSomething(); } // Add a new component var newComponent = myObject.AddComponent<MyComponent>(); // Remove a component myObject.Components.Remove(newComponent);