Esempio n. 1
0
    void DisplayPotionInfo(bool active, int index, bool isBought)
    {
        potion_info_BG.gameObject.SetActive(active);
        accept.gameObject.SetActive(active);
        decline.gameObject.SetActive(active);
        potion_info_Picture.gameObject.SetActive(active);
        potion_info_Picture.sprite = l_potionTypes[l_Inventory[index].m_potionType].GetComponent <SpriteRenderer>().sprite;

        for (int i = 0; i < 2; i++)
        {
            m_texts[i].enabled = active;
        }

        m_texts[0].text = "Cost: " + l_Inventory[index].m_goldCost.ToString();
        m_texts[1].text = l_Inventory[index].m_description;

        if (Input.GetMouseButton(0))
        {
            Ray toMouse     = Camera.main.ScreenPointToRay(Input.mousePosition);
            int layer_mask  = LayerMask.GetMask("button");
            int potion_mask = LayerMask.GetMask("potion");
            if (Physics2D.Raycast(toMouse.origin, toMouse.direction, 999f, layer_mask))
            {
                Transform obj = Physics2D.Raycast(toMouse.origin, toMouse.direction).transform;
                if (obj.name == "potion_accept")
                {
                    for (int i = 0; i < l_Inventory.Count; i++)
                    {
                        if (l_Inventory[i].m_obj.transform == selectedTransform && l_Inventory[i].m_unlocked)
                        {
                            if (m_gold >= l_Inventory[i].m_goldCost && !l_Inventory[i].m_bought)
                            {
                                m_gold = m_gold - l_Inventory[i].m_goldCost;
                                InvetoryPotion inv = new InvetoryPotion();
                                inv          = l_Inventory[i];
                                inv.m_bought = true;
                                SpriteRenderer sr = inv.m_obj.GetComponent <SpriteRenderer>();
                                sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, 1.0f);
                                selectedTransformIndex = i;
                                l_Inventory[i]         = inv;

                                potionSelected    = false;
                                selectedTransform = null;
                                FH.WriteGoldAmount(m_gold.ToString());
                                FH.WriteInventory(i, 1, 1, l_Inventory[i].m_potionType, l_Inventory[i].m_goldCost, l_Inventory[i].m_originalPos);
                                break;
                            }
                            else if (m_gold < l_Inventory[i].m_goldCost)
                            {
                                Debug.Log("cant afford");
                                break;
                            }
                        }
                    }
                }
                else if (obj.name == "potion_decline")
                {
                    potionSelected    = false;
                    selectedTransform = null;
                }
            }
            if (Physics2D.Raycast(toMouse.origin, toMouse.direction, 999f, potion_mask))
            {
                Transform obj = Physics2D.Raycast(toMouse.origin, toMouse.direction).transform;
                for (int i = 0; i < l_Inventory.Count; i++)
                {
                    if (l_Inventory[i].m_obj == obj.gameObject && l_Inventory[i].m_unlocked && selectedTransform == null)
                    {
                        selectedTransformIndex = i;
                        ableToMove             = true;
                        selectedTransform      = obj;
                    }
                }
                if (obj == null)
                {
                    Debug.Log("null");
                    potionSelected         = false;
                    selectedTransform      = null;
                    selectedTransformIndex = 0;
                }
            }
        }
    }