Hi. I want to tell a gameobject to ignore collision with all gameobjects which has “Enemy” tag. But I get this error: BCE0019: ‘collider2D’ is not a member of ‘UnityEngine.GameObject’.
There’s more than one problem with what you’ve done there.
First you’re calling GameObject.FindGameObjectsWithTag(“Enemy”) which returns a LIST of gameobjects, and then you’re asking for its collider2D, which a LIST doesn’t have. You want the collider2D from each member of that list. That’s the error you got there.
Physics2D.IgnoreCollision only takes Collider2D as parameter, and there you’re passing a LIST, which will give you an error after you solved the first problem.
Solution:
foreach(GameObject obj in GameObject.FindGameObjectsWithTag("Enemy")){
Physics2D.IgnoreCollision(collider2D, obj.collider2D);
}
On a side note, if you’re ignoring more than one object you should think about putting those objects in a specific layer and then just use the function Physics2D.IgnoreLayerCollision