public void UpdateBuilState(GameObject[] buildings) { float ratio = 0.8f; foreach (GameObject building in buildings) { TowerPool tower; tower = PoolManager.poolManager.GetTowerParamFromID(ReadFromExcel.ExtractInt(building.name)); int cost = tower.towerAttri.cost; Transform can = building.transform.FindChild("Canvas"); GameObject tex = can.FindChild("Text").gameObject; Text text = tex.transform.GetComponent <Text>(); text.text = "$ " + cost.ToString(); //tex.GetComponent<Text>().text = "$" + cost.ToString(); if (ScoreControl.CheckResourceSuffi(cost) == false) { building.GetComponent <SpriteRenderer>().color = new Color(ratio, ratio, ratio, 1.0f); text.color = new Color(ratio, ratio, ratio, 1.0f); building.GetComponent <BoxCollider2D>().enabled = false; } else { building.GetComponent <BoxCollider2D>().enabled = true; text.color = Color.white; building.GetComponent <SpriteRenderer>().color = Color.white; } } }
public void _ShowUpgrade(UnitTower tower) { Vector3 pos; if (upgradeUI != null) { int upprice = tower.baseTower.upgradeCost; Transform can = upgradeUI.gameObject.transform.FindChild("Canvas"); GameObject tex = can.FindChild("Text").gameObject; Text text = tex.transform.GetComponent <Text>(); text.text = "$" + upprice.ToString(); pos = tower.thisT.position; float height = upgradeUI.GetComponent <BoxCollider2D>().size.y *upgradeUI.transform.localScale.y; if (pos.y + tower.GetComponent <BoxCollider2D>().size.y + height / 2 + 0.05f < maxY) { upgradeUI.transform.position = new Vector3(pos.x, pos.y + tower.GetComponent <BoxCollider2D>().size.y + height / 2 + 0.05f, pos.z); } else { float width = upgradeUI.GetComponent <BoxCollider2D>().size.x *upgradeUI.transform.localScale.x; float width2 = tower.GetComponent <BoxCollider2D>().size.x; upgradeUI.transform.position = new Vector3(pos.x - width2 / 2 - width / 2 - 0.05f, pos.y, pos.z); } upgradeUI.GetComponent <Renderer>().enabled = true; if (ScoreControl.CheckResourceSuffi(upprice) == true && BuildManager.FindUpgrade(ReadFromExcel.ExtractInt(tower.name))) { upgradeUI.GetComponent <SpriteRenderer>().color = Color.white; text.color = Color.white; upgradeUI.GetComponent <BoxCollider2D>().enabled = true; Transform child; if ((child = upgradeUI.transform.FindChild("mouseOver")) != null) { child.GetComponent <Renderer>().enabled = true; } } else { upgradeUI.GetComponent <SpriteRenderer>().color = new Color(0.8f, 0.8f, 0.8f, 1.0f); text.color = new Color(0.8f, 0.8f, 0.8f, 1.0f); upgradeUI.GetComponent <BoxCollider2D>().enabled = false; Transform child; if ((child = upgradeUI.transform.FindChild("mouseOver")) != null) { child.GetComponent <Renderer>().enabled = false; } } } }