Example #1
0
    public void BuyUnit(int i)
    {
        if (occupied[i])
        {
            Bench bench    = new Bench();
            int   benchNmb = bench.GetAvailableBench();
            if (benchNmb < Bench.SIZE)
            {
                Money money = new Money();
                if (money.UseGold(units[i].cost))
                {
                    Upgrade upgrade = new Upgrade();
                    units[i].level = upgrade.NewUnit(units[i].title);
                    for (int j = 1; j < units[i].level; j++)
                    {
                        units[i].attack    = Mathf.RoundToInt(units[i].attack * 1.5f);
                        units[i].health    = Mathf.RoundToInt(units[i].health * 1.5f);
                        units[i].maxHealth = Mathf.RoundToInt(units[i].maxHealth * 1.5f);
                        units[i].armor     = Mathf.RoundToInt(units[i].armor * 1.5f);
                        units[i].resist    = Mathf.RoundToInt(units[i].resist * 1.5f);
                    }
                    if (units[i].level == 4)
                    {
                        units[i].image = Resources.Load <Sprite>("Creature Icons Upgrade/" + units[i].image.name);
                    }

                    bench.AddUnit(units[i], benchNmb);
                    recruits[i].GetComponentInChildren <Image>().enabled       = true;
                    videoPlayer[i].GetComponentInChildren <VideoPlayer>().clip = null;
                    videoPlayer[i].GetComponentInChildren <VideoPlayer>().Stop();
                    Destroy(i);
                }
            }
        }
    }