📜  Unity 在碰撞时销毁游戏对象 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:09.450000             🧑  作者: Mango

代码示例2
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);
    }
}