how to check for collision in unity 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: 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)
}
}