OnCollisionEnter2D code example

Example 1: unity oncollisionenter2d

void OnCollisionEnter2D(Collision2D col)
    {
		//This method will run when your 2D game object
      	//collides with something

      	Debug.Log("Collided");
    }

Example 2: oncollisionenter2d

using UnityEngine;
using System.Collections;public class ExampleClass : MonoBehaviour {
    void OnCollisionEnter2D(Collision2D coll) {
        if (coll.gameObject.tag == "Enemy")
            coll.gameObject.SendMessage("ApplyDamage", 10);
        
    }
}

Example 3: unity 2d collision

void OnCollisionEnter2D(Collision2D col) {
  Debug.Log("Collided with: " + col.gameObject.name);
}

Example 4: oncollisionenter2d

void OnCollisionEnter2D(Collision2D collision) //Make sure to put this out of Voids
    {
        if (other.gameObject.tag == "Object")
        {
            Debug.Log ("Collided");
    	}
    }

Example 5: oncollisionenter2d

OnCollisionEnter2D(Collision2D Collider)