コード例 #1
0
ファイル: Pickup.cs プロジェクト: roogud/Week3
    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;
        }
    }
コード例 #2
0
ファイル: Pickup.cs プロジェクト: roogud/Week3
    protected virtual void DoCollision(Collider2D other)
    {
        PickupGetter getter = other.GetComponent <PickupGetter>();

        if (getter != null)
        {
            PickUp(getter);
        }
    }
コード例 #3
0
    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);
    }
コード例 #4
0
    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);
    }