Search Unity

Im new D: Collisions 2D Destroy help

Discussion in 'Scripting' started by AguaHervida, Aug 1, 2015.

  1. AguaHervida

    AguaHervida

    Joined:
    Jul 28, 2015
    Posts:
    4
    So, I'm starting with unity 5 and i want to destroy an enemy by using a collision in 2D. If the enemy hits the player the player gets destroyed, but if the enemy touches an empty object with rigidbody(its kinematic and gravity 0) and a box collider, the enemy does not destroys.

    This is the code where I destroy the enemy(or at least that's what I hoped for):

    using UnityEngine;
    using System.Collections;

    public class DestroyEnemyCars : MonoBehaviour {

    void OnCollisionEnter2D (Collision2D col)
    {
    if (col.gameObject.tag == "Enemy Car")
    {
    Destroy (col.gameObject);
    Debug.Log ("Something or whaaaaaaaat"); //The console never shows this message :s
    }
    }
    }

    and here i destroy the player:

    void OnCollisionEnter2D(Collision2D col)//llamado cada vez que este gameobject sienta una collision con otro objeto 2D
    {
    if (col.gameObject.tag == "Enemy Car") //se compara con el tag que se hizo
    {
    Destroy (gameObject);
    }
    }
    I really don't know what I'm doing wrong, hope for some help.