Пример #1
0
    private void OnGUI()
    {
        // TODO: the rectangle values are fixed pixel values. Change to be based on screen?

        if (menuOn)
        {
            GUI.BeginGroup(new Rect(Screen.width / 2 - 150, Screen.height / 2 - (Screen.height / 4), Screen.width / 2, Screen.height / 2));

            //the menu background box
            GUI.Box(new Rect(0, 0, 300, 200), "");

            if (GUI.Button(new Rect(10, 10, 130, 80), "Sell Tower for: $" + towerData.sellPrice))
            {
                // do something here
                SellTower();
                GameManager.Instance.Currency += towerData.sellPrice;
                menuOn = false;
                GameManager.Instance.menuActive = false;
            }

            if (GameManager.Instance.Currency < towerData.upgradePrice)
            {
                GUI.color = new Color(1, 1, 1, 0.5f); // set transparency
            }
            else
            {
                GUI.color = new Color(1, 1, 1, 1);
            }

            if (towerData.level == 0)
            {
                if (GUI.Button(new Rect(150, 10, 130, 80), towerData.upgradeName + " \nfor: $" + towerData.upgradePrice) &&
                    GameManager.Instance.Currency >= towerData.upgradePrice)
                {
                    GameManager.Instance.Currency -= towerData.upgradePrice;
                    towerData.UpgradeTower();
                    menuOn = false;
                    GameManager.Instance.menuActive = false;
                }
            }


            GUI.color = new Color(1, 1, 1, 1);
            if (GUI.Button(new Rect(150, 100, 130, 80), "Close"))
            {
                menuOn = false;
                GameManager.Instance.menuActive = false;
            }

            GUI.EndGroup();
        }
    }