Adds a new component of type T
to the GameObject
. The component can be optionally started in an enabled state.
Adds a new component of type T
to the GameObject
. The component can be optionally started in an enabled state.
Use this method to dynamically add a component to a GameObject
at runtime. The startEnabled
parameter determines whether the component should be enabled immediately upon creation.
// Example of adding a component to a GameObject GameObject myGameObject = new GameObject(); MyComponent component = myGameObject.AddComponent<MyComponent>(true);