collision detection unity 3d code example
Example 1: unity how to tell when a gameobject is colliding
void OnCollisionEnter(Collision collision){
if (collision.gameObject.name == "MyGameObjectName")
{
Debug.Log("Do something here");
}
if (collision.gameObject.tag == "MyGameObjectTag")
{
Debug.Log("Do something else here");
}
}
Example 2: unity how to make two objects not collide
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "theobjectToIgnore")
{
Physics.IgnoreCollision(theobjectToIgnore.collider, collider);
}
Example 3: collision detector unity c# 2d
void OnCollisionEnter2D(Collision2D coll){)