how to do collision detection in unity code example
Example 1: unity how to make two objects not collide
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "theobjectToIgnore")
{
Physics.IgnoreCollision(theobjectToIgnore.collider, collider);
}
Example 2: check for collision unity c#
void OnCollisionEnter(Collision col) { }
Example 3: how to do collision tag in unity
void OnColliSionEnter2D(Collision col){
if (col.gameobject.tag == "Enemy"){
Destroy(gameObject)
}
}
Example 4: how to get collision in unity
void OnCollisionEnter(Collision collision)
{
if(Collision.gameObject.name == "Name of object")
{
}
if(Collision.gameObject.tag == "Tag of object")
{
}
}