// when this survivor is placed on a building I need to find out what type it is void OnTriggerStay2D(Collider2D coll) { if (coll.gameObject.tag == "Town_Tile") { townTile = coll.gameObject.GetComponent <TownTile_Properties>(); } }
void Start() { townCentral = GameObject.FindGameObjectWithTag("Town_Central").GetComponent <Town_Central> (); // boost the gather timer // townCentral.gatherTimeBoost = townCentral.gatherTimeBoost + timeBoost; // add habitants to Survivor Vacancies // townCentral.survivorVacancies = townCentral.survivorVacancies + maxHabitants; // townCentral.maxGatherers = townCentral.maxGatherers + maxHabitants; // decrease this town tile's HP because house's lower their defenses townTileProps = GetComponentInParent <TownTile_Properties> (); townTileProps.tileHitPoints = townTileProps.tileHitPoints - hpLoss; }
// checks what Building this survivor has been placed on void ApplyBasicBonus(TownTile_Properties townTile) { // BASIC TILE HP BOOST: All survivors give a slight HP boost when placed // tell the town tile that it has a Survivor on it townTile.hasASurvivor = true; townTile.tileHitPoints = townTile.tileHitPoints + basicHPBoost; // ** CHECK BUILDING FROM EACH OF THE SURVIVOR CLASSES SCRIPT SINCE EACH PROVIDE UNIQUE BONUSES //Check Building and Add Class if (townTile.tileHasTier1 || townTile.tileHasTier2 || townTile.tileHasTier3) { currBuilding = townTile.GetComponentInChildren <Building> (); CheckBuilding(currBuilding); } }
void CalcDamage(int ar, float dmg, TownTile_Properties tile) { int defense = tile.defenseRating; int dmgRoll = (Random.Range(0, ar) + 1) - defense; Debug.Log("HORDE rolls: " + dmgRoll); tile.beingAttacked = true; if (dmgRoll > 0) { float damage = (float)dmgRoll; tile.TakeDamage(damage); } else { print("Miss!"); } canHit = true; }
void CheckBuildingRecipeAndBuild(string name, GameObject towntile) { switch (name) { // case "Slaughterhouse": // if (townResources.wood >= slaughterCost){ // GameObject building = Instantiate (slaughterHouseFab, myTransform.position, Quaternion.identity) as GameObject; // // parent it to the town tile this is on // building.transform.parent = towntile.transform; // // need to makes sure the new gameobject's name matches my hardcoded names // building.name = name; // towntile.name = name; // //then tell this tile that it has an Advanced building // TownTile_Properties townProps = towntile.GetComponent<TownTile_Properties>(); // townProps.tileHasBuilding = false; // no longer has basic building // townProps.tileHasAdvancedBuilding = true; // townResources.wood = townResources.wood - slaughterCost; // } // break; case "Workshop": if (CheckResourceCost(wood: workshopCost[0], stone: workshopCost[1], metal: workshopCost[2])) { GameObject building = Instantiate(workshopFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); townProps.tileHasTier1 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "Stone Workshop": if (CheckResourceCost(wood: stoneWorkshopCost[0], stone: stoneWorkshopCost[1], metal: stoneWorkshopCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DESTROY the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store this oldBuilding in this town tile townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(stoneWorkFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "Metal Workshop": if (CheckResourceCost(wood: metalWorkshopCost[0], stone: metalWorkshopCost[1], metal: metalWorkshopCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DESTROY the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store this oldBuilding in this town tile townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(metalWorkFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "House": if (CheckResourceCost(wood: houseCost[0], stone: houseCost[1], metal: houseCost[2])) { GameObject building = Instantiate(houseFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has a building TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); townProps.tileHasTier1 = true; GetOptionsToShow(towntile); } break; case "Stone House": if (CheckResourceCost(wood: stoneHouseCost[0], stone: stoneHouseCost[1], metal: stoneHouseCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DESTROY the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store this oldBuilding in this town tile townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(stoneHouseFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "Metal House": if (CheckResourceCost(wood: metalHouseCost[0], stone: metalHouseCost[1], metal: metalHouseCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DESTROY the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store this oldBuilding in this town tile townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(metalHouseFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "Basic Defense": if (CheckResourceCost(wood: basicDefenseCost[0], stone: basicDefenseCost[1], metal: basicDefenseCost[2])) { GameObject building = Instantiate(basicDefenseFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has a building TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); townProps.tileHasTier1 = true; GetOptionsToShow(towntile); } break; case "Stone Defense": if (CheckResourceCost(wood: stoneDefenseCost[0], stone: stoneDefenseCost[1], metal: stoneDefenseCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DESTROY the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store this oldBuilding in this town tile townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(stoneDefenseFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "Metal Defense": if (CheckResourceCost(wood: metalDefenseCost[0], stone: metalDefenseCost[1], metal: metalDefenseCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DISABLE the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store the Tier 1 bulding townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item // and turn it off oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(metalDefenseFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "Auto-Cannon": if (CheckResourceCost(wood: metalDefenseCost[0], stone: metalDefenseCost[1], metal: metalDefenseCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DISABLE the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store the Tier 2 bulding townProps.deactivatedT2 = oldBuilding[1].gameObject; // DONT actually turn it off so we can have a nice wall background for now // oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(autoCanFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = false; townProps.tileHasTier3 = true; // now has Tier 3 buiding } break; case "Stone-Thrower": if (CheckResourceCost(wood: metalDefenseCost[0], stone: metalDefenseCost[1], metal: metalDefenseCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DISABLE the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store the Tier 2 bulding townProps.deactivatedT2 = oldBuilding[1].gameObject; // DONT actually turn it off so we can have a nice wall background for now // oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(throwFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = false; townProps.tileHasTier3 = true; // now has Tier 3 buiding } break; case "Catapult": if (CheckResourceCost(wood: metalDefenseCost[0], stone: metalDefenseCost[1], metal: metalDefenseCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DISABLE the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store the Tier 1 bulding townProps.deactivatedT2 = oldBuilding[1].gameObject; // DONT actually turn it off so we can have a nice wall background for now // oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(catapFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = false; townProps.tileHasTier3 = true; // now has Tier 3 buiding } break; case "Farm": if (CheckResourceCost(wood: farmCost[0], stone: farmCost[1], metal: farmCost[2])) { GameObject building = Instantiate(farmFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has a building TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); townProps.tileHasTier1 = true; GetOptionsToShow(towntile); } break; case "Stone Farm": if (CheckResourceCost(wood: stoneFarmCost[0], stone: stoneFarmCost[1], metal: stoneFarmCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DESTROY the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store this oldBuilding in this town tile townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(stoneFarmFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "Metal Farm": if (CheckResourceCost(wood: metalFarmCost[0], stone: metalFarmCost[1], metal: metalFarmCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DISABLE the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store the Tier 1 bulding townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item // and turn it off oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(metalFarmFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; case "Drone Tower": if (CheckResourceCost(wood: droneTowCost[0], stone: droneTowCost[1], metal: droneTowCost[2])) { TownTile_Properties townProps = towntile.GetComponent <TownTile_Properties>(); // Need to DESTROY the old house in this towntile (use an array to get the child) Transform[] oldBuilding = towntile.GetComponentsInChildren <Transform>(); // store this oldBuilding in this town tile townProps.deactivatedT1 = oldBuilding[1].gameObject; // since the first Transform of the array is always the parent, access the second item oldBuilding[1].gameObject.SetActive(false); GameObject building = Instantiate(droneTowFab, myTransform.position, Quaternion.identity) as GameObject; // parent it to the town tile this is on building.transform.parent = towntile.transform; // need to makes sure the new gameobject's name matches my hardcoded names building.name = name; towntile.name = name; //then tell this tile that it has an Advanced building townProps.tileHasTier1 = false; // no longer has basic building townProps.tileHasTier2 = true; // CHECK to see what options to show next GetOptionsToShow(towntile); } break; default: print("Not enough resources!"); break; } }
void DestroyBuilding(GameObject town) { Transform[] children = town.GetComponentsInChildren <Transform> (); TownTile_Properties townProps = town.GetComponent <TownTile_Properties>(); // find the BUILDING on the town tile Building building = town.GetComponentInChildren <Building> (); // subtract ALL BONUSES and give back ALL PENALTIES building.SubtractBonuses(building.myBuildingType, building.gameObject); // IF TILE ONLY HAS 1 BUILDING then when we destroy we need to deactivate build buttons if (townProps.tileHasTier1) // only destroy Tier 1 building { Destroy(children [1].gameObject); // Change parent name to something else townTile.name = "Town X"; townProps.tileHasTier1 = false; // // then deActivate build buttons firstBuildBtn.gameObject.SetActive(false); secondBuildBtn.gameObject.SetActive(false); thirdBuidBtn.gameObject.SetActive(false); fourthBuildBtn.gameObject.SetActive(false); showBuildButtons = false; // then allow mouse to select again stopMouse = false; } else if (townProps.tileHasTier2) { Destroy(children [1].gameObject); // destroy the Tier 2 building if (townProps.deactivatedT1 != null) { townProps.deactivatedT1.SetActive(true); // activate Tier 1 building // Change name back to Tier 1 building name townTile.name = townProps.deactivatedT1.name; townProps.tileHasTier2 = false; // tile no longer has Tier 2 building townProps.tileHasTier1 = true; // tile now has Tier 1 building // CHECK to see what options to show next GetOptionsToShow(town); } else { townTile.name = "Town S"; // in case it can't find the T1 building, everything goes false townProps.tileHasTier2 = false; townProps.tileHasTier1 = false; // CHECK to see what options to show next GetOptionsToShow(town); } } else if (townProps.tileHasTier3) { Destroy(children [2].gameObject); // destroy the Tier 3 building (using index 2 because im not turning off the wall) if (townProps.deactivatedT2 != null) { // townProps.deactivatedT2.SetActive(true); // Change name back to Tier 2 building name townTile.name = townProps.deactivatedT2.name; townProps.tileHasTier3 = false; // tile no longer has Tier 3 building townProps.tileHasTier2 = true; // tile now has Tier 2 building // CHECK to see what options to show next GetOptionsToShow(town); } else { townTile.name = "Town S"; // in case it can't find the T2 building, everything goes false townProps.tileHasTier3 = false; townProps.tileHasTier2 = false; townProps.tileHasTier1 = false; // CHECK to see what options to show next GetOptionsToShow(town); } } }
// Use this for initialization void Start() { townTileProps = GetComponentInParent <TownTile_Properties> (); townTileProps.tileHitPoints = townTileProps.tileHitPoints + hitPointsBoost; }
void Awake() { townTile = GetComponent <TownTile_Properties> (); }