After doing some video tutorials on Youtube, I recognized that these two Classes look similar and repetitive.
-Collision2D-
This method called when an incoming collider makes contact with this object's collider (2D physics only)
void OnCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "Enemy")
coll.gameObject.SendMessage("ApplyDamage", 10);
}
-Collider2D-
This method called when another collider makes contact with this object
void OnTriggerEnter2D(Collider2D other) {
Destroy (other.gameObject);
}
Both methods have same purpose and look the same. What is the difference?
Collision2D
contains the info about the collision, whileCollider2D
is a component of the colliding object.http://docs.unity3d.com/ScriptReference/Collision2D.html http://docs.unity3d.com/ScriptReference/Collider2D.html
As you can see, the purpose is similar, but not the same.