2
votes

I have this script attached to my bullet, which is currently just cube in 2d space. it has rigidbody2d, boxcollider and istrigger is checked.

using UnityEngine; using System.Collections;

public class EnemyBulletCollision : MonoBehaviour {

void OnTriggerEnter(Collision coll)
{
    if(coll.gameObject.tag == "Enemy") {
        Destroy(coll.gameObject);
        Destroy(gameObject);
    }
}

}

Enemy is also cube with BoxCollider, Rigidbody2d and istrigger checked. Nothing just happens. i tried all kind of things, but none works. Kind of stuck here.

1

1 Answers

2
votes

When you use Unity's 2D physics, you must use the corresponding 2D methods (all the same methods, just ending with "2D"). So instead of using OnTriggerEnter, you need to use OnTriggerEnter2D.