using UnityEngine; using System.Collections; public class IgnoreCollision : MonoBehaviour { public Collider2D otherCollider; void Start () { Physics2D.IgnoreCollision(GetComponent(), otherCollider); } }
using UnityEngine; using System.Collections; public class Enemy : MonoBehaviour { public GameObject player; void Update () { if (Physics2D.GetIgnoreCollision(GetComponentIn this example, the GetIgnoreCollision method is called in the Update function of the script. It takes the Collider2D component of the game object the script is attached to and another Collider2D component specified in the "player" variable. The function will return a Boolean value indicating whether the collision between the two should be ignored. If it returns true, the script will perform some action. The Physics2D.GetIgnoreCollision method is part of the UnityEngine.Physics2D package library.(), player.GetComponent ())) { // Do something if the collison is ignored } } }