void showCost(BuildingObjectParameter obp) { panel.SetActive(true); showPriceText.text = ""; if (obp.woodCost > 0) { showPriceText.text += "Wood: " + obp.woodCost + "/" + rManger.GetWood(PlayerTypes.humanPlayer) + " "; } if (obp.stoneCost > 0) { showPriceText.text += "Stone: " + obp.stoneCost + "/" + rManger.GetStone(PlayerTypes.humanPlayer) + " "; } }
public void setPrefab(GameObject newPrefab) { if (currentPlaceableObject != null) { Destroy(currentPlaceableObject); } prefab = newPrefab; BuildingObjectParameter op = newPrefab.GetComponent <BuildingObjectParameter>(); showCost(op); op.playerTypes = PlayerTypes.humanPlayer; woodCost = op.GetWoodCost(); stoneCost = op.GetStoneCost(); }
public void build(Building building) { int loops = 10; isBuild = false; Debug.Log("AI Building"); BuildingObjectParameter bop = building.buildingType.GetComponent <BuildingObjectParameter>(); if (ResourceManager.Instance.PurchaseBuilding(bop.woodCost, bop.stoneCost, PlayerTypes.AIPlayer)) { while (!isBuild) { Vector3 centre = transform.position; Vector2 randomPos = Random.insideUnitCircle * BuildingRadius; Vector3 v = centre + new Vector3(randomPos.x, 10, randomPos.y); RaycastHit hit; if (Physics.Raycast(v, Vector3.down, out hit, 20.0f)) { if (hit.collider.tag == "Ground" && !Physics.CheckBox(hit.point, DistanceBetweenBuildings, Quaternion.identity, SphereCheck)) { if (grid.checkNodesAreEmpty(hit.point, 4)) { bop.playerTypes = PlayerTypes.AIPlayer; building.buildingType.tag = "Enemy"; GameObject constructed = Instantiate(building.buildingType, hit.point, Quaternion.identity); buildingsInGame.Add(constructed); grid.SetNodeUnwakable(constructed); isBuild = true; animator.SetBool(building.name, true); } } } loops++; } Debug.Log("Num Loops: " + loops); } else { animator.SetBool("missing", true); } }