How To Add Component In Unity C# Code Example


Example 1: Add component object to gameobject unity


//to add a new ridgidbody
gameobject.AddComponent<Rigidbody>();
//to add a new meshCollider
gameobject.AddComponent<MeshCollider>();
//Original answer by MakerBenjammin6, cleanup by me.

Example 2: unity add component


//Use the AddComponent<T>() Method to add a component to your gameobject
GameObject gameObject;

gameObject.AddComponent<BoxCollider>(); //Component has to be an actual Unity component

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android SDK Location Should Not Contain Whitespace, As This Cause Problems With NDK Tools