Collider2D vs Collision2D

核能气质少年 提交于 2019-12-08 04:50:19

问题


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:


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.



来源:https://stackoverflow.com/questions/28800678/collider2d-vs-collision2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!