Collider2D vs Collision2D

2019-06-02 10:25发布

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?

1条回答
走好不送
2楼-- · 2019-06-02 10:48

Collision2D contains the info about the collision, while Collider2D 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.

查看更多
登录 后发表回答