public virtual void PickUp(PickupGetter getter) { //if we were already picked up, don't allow it again if (wasPickedUp) { return; } wasPickedUp = true; getter.PickUp(this); if (type == PickupType.Consumable) { Destroy(gameObject); } else { //if we're hidden, we need to destroy the sprite renderers attached. //we look in the children in case we have one nested. if (type == PickupType.HiddenOnPickup) { Destroy(GetComponentInChildren <SpriteRenderer>()); } //we don't need our collider or physics anymore //since Destroy() ignores a null parameter, it's okay to assume we have these components. Destroy(GetComponent <Collider2D>()); Destroy(GetComponent <Rigidbody2D>()); //parent us to the guy who picked us up transform.parent = getter.transform; transform.localPosition = Vector3.zero; } }
protected virtual void DoCollision(Collider2D other) { PickupGetter getter = other.GetComponent <PickupGetter>(); if (getter != null) { PickUp(getter); } }
public override void PickUp(PickupGetter getter) { //first, give health back, if applicable Destructible destructible = getter.GetComponent <Destructible>(); if (destructible != null) { destructible.RecoverHitPoints(recoveryAmount); } //then, do our default behavior base.PickUp(getter); }
public override void PickUp(PickupGetter getter) { //first, give health back, if applicable Jumper jumper = getter.GetComponent <Jumper>(); if (jumper != null) { jumper.jumpImpulse += jumpImpulseIncrease; } //then, do our default behavior base.PickUp(getter); }