Pick up and Destroy Unity 5 Object

Use this code when you want your character to pick up an object e.g. Coins. Create a empty JavaScript file in Unity 5 and add the following line of code. Then drag and drop the JavaScript file onto any object you want to destroy when you touch it with a collider. The collider must have Is Trigger switched on.

function OnTriggerEnter (info : Collider) {
Destroy(gameObject);
}

Leave a Comment