Пример #1
0
        /// <summary>
        /// Add item to player and its inventory.
        /// </summary>
        /// <param name="target">Target Player character which will get the item.</param>
        /// <param name="item">Item to add.</param>
        public void AddItem(Player target, SpecialItem item)
        {
            Sprite previousItem = null;

            // Go through all item slots.
            for (int i = 0; i < transform.childCount; i++)
            {
                // Get image component of the slot.
                Image img = transform.GetChild(i).GetChild(0).GetComponent <Image>();

                // First slot.
                if (i == 0)
                {
                    img.enabled = true;

                    previousItem = img.sprite;
                    img.sprite   = item.GetComponent <SpriteRenderer>().sprite;
                    continue;
                }

                // Another slots.
                // If there is no item to move from the first slot, we dont need to continue.
                if (previousItem == null)
                {
                    break;
                }

                img.enabled = true;

                Sprite currentItem = img.sprite;                 // Auxiliary variable.
                img.sprite   = previousItem;
                previousItem = currentItem;

                // Remove item which overflows.
                if (i == transform.childCount - 1 && previousItem != null)
                {
                    target.SpecialItemList.Remove(target.SpecialItemList.First());
                }
            }

            // Add item's special status effect to player's inventory.
            target.SpecialItemList.Add(item.GetComponent <SpecialItem>().ItemStatusEffect);
        }
Пример #2
0
    public float DoSpecial(SpecialItem item)
    {
        var animator = item.GetComponent <Animator>();

        if (animator != null)
        {
            animator.Play("Action");
        }
        switch (item.type)
        {
        case Special.jump:
            SetUp(GenderPack.side);
            anim.Play("Jump");
            return(6f);

        case Special.swim:
            SetUp(GenderPack.side);
            anim.Play("Swimming");
            return(9.67f);

        case Special.run:
            SetUp(GenderPack.side);
            anim.Play("Run");
            return(5f);

        case Special.sleep:
            SetUp(GenderPack.down);
            anim.Play("Sleep");
            return(6f);

        case Special.scratch:
            SetUp(GenderPack.side);
            anim.Play("Scratch");
            return(1.30f);

        case Special.mud:
            SetUp(GenderPack.side);
            anim.Play("Mud");
            return(5f);

        default:
            return(0);
        }
    }