Ejemplo n.º 1
0
    private void RefreshInventoryList()
    {
        foreach (Transform child in itemSlotContainer)
        {
            if (child == itemSlotTemplate)
            {
                continue;
            }
            Destroy(child.gameObject);
        }


        int   x = 0;
        int   y = 0;
        float itemSlotCellSize = 370f;

        foreach (Item item in inventory.GetItemList())
        {
            RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>();
            itemSlotRectTransform.gameObject.SetActive(true);

            itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () =>
            {
                //Use item
                inventory.UseItem(item);
            };
            itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () =>
            {
                //Drop item
                Item duplicateItem = new Item {
                    itemType = item.itemType, Amount = item.Amount
                };
                inventory.RemoveItem(item);
                ItemWorld.DropItem(player.GetPosition(), duplicateItem);
            };

            itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize);
            Image image = itemSlotRectTransform.Find("image").GetComponent <Image>();
            image.sprite = item.GetSprite();
            TextMeshProUGUI uiText = itemSlotRectTransform.Find("text").GetComponent <TextMeshProUGUI>();

            if (item.Amount > 1)
            {
                uiText.SetText(item.Amount.ToString());
            }
            else
            {
                uiText.SetText("");
            }

            x++;
            if (x > 4)
            {
                x = 0;
                y++;
            }
        }
    }
Ejemplo n.º 2
0
    private void PlayerCharacterHandler_OnEnemyKilled(object sender, EnemyHealth.OnEnemyKilledEventArgs e)
    {
        // Vector3 enemyPos = GetComponent<EnemyCharacterHandler>().ActualEnemyPosition;

        Vector3 flyDirection = (enemyCharacterHandler.GetPosition() - playerCharacterHandler.GetPosition()).normalized;

        FlyingBody.Create(pfEnemyDeadBody, enemyCharacterHandler.GetPosition(), flyDirection);
        enemy.SetActive(false);
        UtilsClass.ShakeCamera(2f, .1f);
    }