How to Destroy a GameObject on Collision in Unity
How to Destroy a GameObject on Collision in Unity
Example for destroy a gameObct:
- Pickup a coin when the player collide with the Coin.
 - shoot a bullet and destroy The Enemy.
 - Destroy a gameObgect when itcollide with the Floor.
 
Exeple for Player pickup the Coin :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CurrencyPickup : MonoBehaviour
{
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.gameObject.tag == "Coin")
        {
            Destroy(other.gameObject);
        }
    }
}
The player and coin must have a collider component, in the collider of the coin set Trigger case enable.
Tag: Destroy prefab unity,Unity destroy and spawn object, Unity destroy object on collision,Unity movement script,How to destroy another object in Unity,How to Instantiate a GameObject Unity,Unity Destroy object after time     

Post a Comment
image video quote pre code