OnCollisionEnter2D unity code example
Example 1: unity oncollisionenter2d
void OnCollisionEnter2D(Collision2D col)
{
Debug.Log("Collided");
}
Example 2: unity oncollisionenter
void OnCollisionEnter(Collision col)
{
Debug.Log("Collided");
}
Example 3: oncollisionenter unity
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Door")
{
DoorScript script = collision.gameObject.GetComponent<DoorScript>();
script.OpenDoor();
}
}
Example 4: 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 5: oncollisionenter2d
void OnCollisionEnter2D(Collision2D collision)
{
if (other.gameObject.tag == "Object")
{
Debug.Log ("Collided");
}
}
Example 6: oncollisionenter2d
OnCollisionEnter2D(Collision2D Collider)