示例#1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag != "Items" && other.gameObject.layer == 2)
        {
            TriggerHit++;
        }
        else if (other.tag == "Items" && other.GetComponent <Item_To_Pick_Up>())
        {
            if (isColliding)
            {
                return;
            }
            else
            {
                isColliding = true;
            }

            GameObject ItemPickUp = other.GetComponent <Item_To_Pick_Up>().PickUpItem;
            if (ItemPickUp.GetComponent <Drag_Inventory>() && ItemPickUp.GetComponent <Drag_Inventory>().typeOfItem == Drag_Inventory.Slot.Ammo)
            {
                Drop_Inventory DropA = menuManager.Ammo_Slot.GetComponent <Drop_Inventory>();
                //If the player has room in their ammo inventory, pick up the item
                if (DropA.NumberOfSlotsFilled < DropA.NumberOfSlotsTotal)
                {
                    //MenuTimer = 0.05f;
                    //Spawn item
                    GameObject Item = (GameObject)Instantiate(ItemPickUp);
                    Item.name = ItemPickUp.name;
                    Item.GetComponent <Ammo_Types>().Amount = other.GetComponent <Ammo_Types>().Amount;
                    //Set its parent to the ammo inventory
                    Item.transform.SetParent(DropA.transform);
                    //Sets default scale
                    Item.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f);
                    //Incresses slots filled count
                    if (menuManager.Ammo_Slot.GetComponent <Ammo_Inventory>().CombindStacks())
                    {
                        DropA.NumberOfSlotsFilled = menuManager.Ammo_Slot.transform.childCount - 1; //has a chance that and additional ammo can be added into the inventory
                    }
                    Destroy(other.gameObject);

                    if (PickupSound != null)
                    {
                        PickupSound.Play();
                    }
                }
            }
        }
    }
示例#2
0
    private void ItemPickUp(Collider other)
    {
        GameObject     ItemPickUp = other.GetComponent <Item_To_Pick_Up>().PickUpItem;
        Drop_Inventory DropI      = InventorySlot.GetComponent <Drop_Inventory>();

        if (ItemPickUp.GetComponent <Drag_Inventory>() && ItemPickUp.GetComponent <Drag_Inventory>().typeOfItem == Drag_Inventory.Slot.Ammo)
        {
            Drop_Inventory DropA = menuManager.Ammo_Slot.GetComponent <Drop_Inventory>();
            //If the player has room in their ammo inventory, pick up the item
            if (DropA.NumberOfSlotsFilled < DropA.NumberOfSlotsTotal)
            {
                MenuTimer = 0.05f;
                //Spawn item
                GameObject Item = (GameObject)Instantiate(ItemPickUp);
                Item.name = ItemPickUp.name;
                Item.GetComponent <Ammo_Types>().Amount = other.GetComponent <Ammo_Types>().Amount;
                //Set its parent to the ammo inventory
                Item.transform.SetParent(DropA.transform);
                //Sets default scale
                Item.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f);
                //Incresses slots filled count
                if (menuManager.Ammo_Slot.GetComponent <Ammo_Inventory>().CombindStacks())
                {
                    DropA.NumberOfSlotsFilled = menuManager.Ammo_Slot.transform.childCount - 1; //has a chance that and additional ammo can be added into the inventory
                }
                Destroy(other.gameObject);

                if (PickupSound != null)
                {
                    PickupSound.Play();
                }
            }
        }
        //If the player has room in their inventory, pick up the item
        else if (DropI.NumberOfSlotsFilled < DropI.NumberOfSlotsTotal && ItemPickUp.GetComponent <Drag_Inventory>().typeOfItem != Drag_Inventory.Slot.Ammo)
        {
            MenuTimer = 0.05f;
            //Spawn item
            GameObject Item = (GameObject)Instantiate(ItemPickUp);
            Item.name = ItemPickUp.name;
            //Set its parent to the inventory
            Item.transform.SetParent(DropI.transform);
            //Sets default scale
            Item.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f);
            //Incresses slots filled count
            DropI.NumberOfSlotsFilled++;

            if (Item.GetComponent <ItemStats>() && other.transform.GetChild(0).GetComponent <Gun_Behaviour>())
            {
                //Debug.Log("Pickup : Before " + Item.GetComponent<ItemStats>().itemStats[4].baseValue + " After " + other.transform.GetChild(0).GetComponent<Gun_Behaviour>().Stats[4].baseValue);
                Item.GetComponent <ItemStats>().itemStats = other.transform.GetChild(0).GetComponent <Gun_Behaviour>().Stats;
            }

            //Destroy item on ground
            Destroy(other.gameObject);

            if (PickupSound != null)
            {
                PickupSound.Play();
            }
        }
    }