Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Collision2D

Collision details returned by 2D physics callback functions.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Class
  • Namespace: UnityEngine
  • Assembly: UnityEngine.Physics2DModule
public class Collision2D

Remarks

The collisions details are returned by MonoBehaviour.OnCollisionEnter2D(Collision2D), MonoBehaviour.OnCollisionStay2D(Collision2D) and MonoBehaviour.OnCollisionExit2D(Collision2D) callbacks. It details which Collider2D and Rigidbody2D pairs are involved in the collision as well as contact points where the Collider2D meet. Note: During the
OnCollisionExit2D
event, there are no contacts to be retrieved.

Properties

Property

Description

colliderThe incoming Collider2D involved in the collision with the Collision2D.otherCollider.
contactCountGets the number of contacts for this collision.
contactsThe specific points of contact with the incoming Collider2D. You should avoid using this as it produces memory garbage. Use Collision2D.GetContact or Collision2D.GetContacts instead.
enabledIndicates whether the collision response or reaction is enabled or disabled.
gameObjectThe incoming GameObject involved in the collision.
otherColliderThe other Collider2D involved in the collision with the Collision2D.collider.
otherRigidbodyThe other Rigidbody2D involved in the collision with the Collision2D.rigidbody.
relativeVelocityThe relative linear velocity of the two colliding objects (Read Only).
rigidbodyThe incoming Rigidbody2D involved in the collision with the Collision2D.otherRigidbody.
transformThe Transform of the incoming object involved in the collision.

Methods

Method

Description

GetContactGets the contact point at the specified index.
GetContactsRetrieves all contact points for contacts between Collision2D.collider and Collision2D.otherCollider.