add component to gameobject unity code example
Example 1: unity add component
GameObject gameObject;
gameObject.AddComponent<BoxCollider>();
Example 2: c# addcomponent
Rigidbody addedComp = gameObj.AddComponent<Rigidbody>() as Rigidbody;
Example 3: unity adding component to another gameobject
public GameObject exampleObject;
private Rigidbody rb;
public void Awake() {
rb = exampleObject.AddComponent<Rigidbody>();
rb = exampleObject.GetComponent<Rigidbody>();
}
Example 4: how to add a componet to a gameobject throgh code unity
gameobject.addComponet<ridgidbody>();
gameobject.addComponet<MeshCollider>();