Answers for "when enters collider destroy a gameobject unity"

C#
2

unity deactivate all colliders of a gameobject

public void SetAllCollidersStatus (bool active) {
     foreach(Collider c in GetComponents<Collider> ()) {
         c.enabled = true; //Or false if you want to desactivate them all
     }
 }
Posted by: Guest on May-08-2021
1

Unity Destroy gameObject upon collision

void OnCollisionEnter2D(Collision2D collision)
{
    Destroy(gameOnject);
}

// Or if you only want it to be destroyed when 
// hitting something specific

void OnCollisionEnter2D(Collision2D collision)
{
    if(collision.gameObject.tag == "tag")
    {
         Destroy(gameObject);
    }
}
Posted by: Guest on September-30-2021

Code answers related to "when enters collider destroy a gameobject unity"

C# Answers by Framework

Browse Popular Code Answers by Language