SpriteFactory.SpriteCollider.CollisionData.GetCollider
C#: TCollider GetCollider<TCollider> ()
JS: function GetCollider.<TCollider> () : TCollider
Description
Generic function. Get the collider cast to a specific type. TCollider must be derrived from either Collider or Collider2D.
Example:
C#
void OnCollisionEnterSprite(SpriteFactory.SpriteCollider.CollisionData collisionData) { // Get the name of the collider that collided with this Sprite // The long way (involves casting) if(collisionData.is2D) { Collision collision = (Collision2D)collisionData.objectValue; // get the Collision2D object from collisionData Collider2D otherCollider = collision.collider; // get the other collider that collided with this collider Debug.Log(collisionData.spriteColliderName + " collided with " + otherCollider.name); } else { Collision collision = (Collision)collisionData.objectValue; // get the Collision object from collisionData Collider otherCollider = collision.collider; // get the other collider that collided with this collider Debug.Log(collisionData.spriteColliderName + " collided with " + otherCollider.name); } // The faster way if(collisionData.is2D) { Debug.Log(collisionData.spriteColliderName + " collided with " + collisionData.GetCollider<Collider2D>().name); } else { Debug.Log(collisionData.spriteColliderName + " collided with " + collisionData.GetCollider<Collider>().name); } }