Answers for "how to destroy gameobject when collision 2d"

C#
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
-1

how to destroy a gameobject permanently unity when player go through it 2d

hkgdkydg
Posted by: Guest on August-05-2020

Code answers related to "how to destroy gameobject when collision 2d"

C# Answers by Framework

Browse Popular Code Answers by Language