示例#1
0
    private void OnTriggerEnter(Collider other)
    {
        IPickup pickup = other.GetComponent <IPickup>();

        if (pickup != null)
        {
            pickup.Pickup(); //Do something when you hit the object
        }
    }
示例#2
0
        public void Pickup(IItem item)
        {
            IPickup itemPickup = item.GetPickup();
            bool    win        = itemPickup.Pickup(this);

            if (win)
            {
                game.SetState(game.WIN);
            }
        }
    private void OnTriggerEnter(Collider other)
    {
        // Already holding something
        if (pickup != null)
        {
            return;
        }

        IPickup otherPickup = other.GetComponent <IPickup>();

        if (otherPickup == null)
        {
            otherPickup = other.GetComponentInParent <IPickup>();
        }

        if (otherPickup != null && otherPickup != lastPickup)
        {
            // Attempt Pickup
            if (otherPickup.Pickup(this))
            {
                pickup = otherPickup;
            }
        }
    }