SpriteFactory.ColliderInfo.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#
ColliderInfo colliderInfo = sprite.GetCollider("HitCollider"); // get the collider from the sprite
if(colliderInfo.is2D) { // this is a 2D collider
if(colliderInfo.type == ColliderType.Box) {
BoxCollider2D box2D = colliderInfo.GetCollider<BoxCollider2D>(); // get the collider cast to the proper type
// do something
}
} else { // this is a 3D collider
if(colliderInfo.type == ColliderType.Box) {
BoxCollider box = colliderInfo.GetCollider<BoxCollider>(); // get the collider cast to the proper type
}
}