I have objects: a wall and a player that shoots “something”.
Both are prefabs and are loaded dynamically like this:
Transform bulletClone = GameObject.Instantiate (shootTile, playerPos, Quaternion.identity) as Transform;
Instantiate (Wall, new Vector3 (x, y), Quaternion.identity);
They actually collide, but they do not trigger my following function:
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log (collision.gameObject.tag);
if(collision.gameObject.name == "enemy"){
Destroy(this.gameObject);
}
}
I have a rigidBody2D on the bullet, with a Box Collider 2d.
On the wall I also have Box Collider 2D.
My player has both a ridigBody2D and a BoxCollider2D, and that is triggering on the bullet AND the wall. But for some reason it is not triggering for my instantiated objects