private void checkCollsions() { // Villagers x Monsters foreach (GameObject vilObj in villagers) { Villager villager = vilObj.GetComponent(typeof(Villager)) as Villager; BoxCollider2D villagerBounds = vilObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D villagerRange = vilObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; foreach (GameObject monObj in monsters) { Monster monster = monObj.GetComponent(typeof(Monster)) as Monster; BoxCollider2D monsterBounds = monObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D monsterRange = monObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; if (villagerRange.bounds.Intersects(monsterBounds.bounds)) { villager.attack(monster); } } } //Villagers x Buildings foreach (GameObject vilObj in villagers) { Villager villager = vilObj.GetComponent(typeof(Villager)) as Villager; BoxCollider2D villagerBounds = vilObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D villagerRange = vilObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; if (villager.currentFood > 0 || villager.currentWood > 0 || villager.currentStone > 0) { foreach (GameObject buiObj in buildings) { UtilityBuilding uBuilding = buiObj.GetComponent(typeof(UtilityBuilding)) as UtilityBuilding; BoxCollider2D buildingBounds = buiObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D buildingRange = buiObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; if (uBuilding != null) { if (villagerRange.bounds.Intersects(buildingBounds.bounds)) { if (uBuilding.currentFood < uBuilding.foodStorage) { uBuilding.currentFood += villager.currentFood; villager.currentFood = 0; if (uBuilding.currentFood > uBuilding.foodStorage) { uBuilding.currentFood = uBuilding.foodStorage; } } if (uBuilding.currentWood < uBuilding.woodStorage) { uBuilding.currentWood += villager.currentWood; villager.currentWood = 0; if (uBuilding.currentWood > uBuilding.woodStorage) { uBuilding.currentWood = uBuilding.woodStorage; } } if (uBuilding.currentStone < uBuilding.stoneStorage) { uBuilding.currentStone += villager.currentStone; villager.currentStone = 0; if (uBuilding.currentStone > uBuilding.stoneStorage) { uBuilding.currentStone = uBuilding.stoneStorage; } } } } } } } //Villager x Zones foreach (GameObject vilObj in villagers) { Villager villager = vilObj.GetComponent(typeof(Villager)) as Villager; BoxCollider2D villagerBounds = vilObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D villagerRange = vilObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; if (villagerRange.bounds.Intersects(woodZone.GetComponent <BoxCollider2D>().bounds)) { villager.inGatherZone = true; villager.gatherZoneType = "Wood"; } else if (villagerRange.bounds.Intersects(stoneZone.GetComponent <BoxCollider2D>().bounds)) { villager.inGatherZone = true; villager.gatherZoneType = "Stone"; } else if (villagerRange.bounds.Intersects(foodZone.GetComponent <BoxCollider2D>().bounds)) { villager.inGatherZone = true; villager.gatherZoneType = "Food"; } else { villager.inGatherZone = false; villager.gatherZoneType = ""; } } // Monsters x Villagers foreach (GameObject monObj in monsters) { Monster monster = monObj.GetComponent(typeof(Monster)) as Monster; BoxCollider2D monsterBounds = monObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D monsterRange = monObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; foreach (GameObject vilObj in villagers) { Villager villager = vilObj.GetComponent(typeof(Villager)) as Villager; BoxCollider2D villagerBounds = vilObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D villagerRange = vilObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; if (monsterRange.bounds.Intersects(villagerBounds.bounds)) { monster.attack(villager); } } } // Buildings x Monsters foreach (GameObject buiObj in buildings) { DefenseBuilding building = buiObj.GetComponent(typeof(DefenseBuilding)) as DefenseBuilding; BoxCollider2D buildingBounds = buiObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D buildingRange = buiObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D;//buiObj.GetComponent(typeof(CircleCollider2D)) as CircleCollider2D; if (building != null) { foreach (GameObject monObj in monsters) { Monster monster = monObj.GetComponent(typeof(Monster)) as Monster; BoxCollider2D monsterBounds = monObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D monsterRange = monObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; if (buildingRange.bounds.Intersects(monsterBounds.bounds)) { building.attack(monster); } } } } // Monsters x Buildings foreach (GameObject monObj in monsters) { Monster monster = monObj.GetComponent(typeof(Monster)) as Monster; BoxCollider2D monsterBounds = monObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D monsterRange = monObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; foreach (GameObject buiObj in buildings) { Building building = buiObj.GetComponent(typeof(Building)) as Building; BoxCollider2D buildingBounds = buiObj.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D; CircleCollider2D buildingRange = buiObj.GetComponentInChildren(typeof(CircleCollider2D)) as CircleCollider2D; if (building != null && monsterRange.bounds.Intersects(buildingBounds.bounds)) { monster.attack(building); } } } }
public void showInfoPanel(GameObject obj) { hideInfoPanels(); Character character = obj.GetComponent(typeof(Character)) as Character; DefenseBuilding dBuilding = obj.GetComponent(typeof(DefenseBuilding)) as DefenseBuilding; UtilityBuilding uBuilding = obj.GetComponent(typeof(UtilityBuilding)) as UtilityBuilding; if (character != null) { characterInfoPanel.SetActive(true); Text type = characterInfoPanel.transform.Find("TypeText").gameObject.GetComponent <Text>(); Text hp = characterInfoPanel.transform.Find("HPText").gameObject.GetComponent <Text>(); Text atk = characterInfoPanel.transform.Find("ATKText").gameObject.GetComponent <Text>(); Text def = characterInfoPanel.transform.Find("DEFText").gameObject.GetComponent <Text>(); Text mgk = characterInfoPanel.transform.Find("MGKText").gameObject.GetComponent <Text>(); Text wil = characterInfoPanel.transform.Find("WILText").gameObject.GetComponent <Text>(); Text spd = characterInfoPanel.transform.Find("SPDText").gameObject.GetComponent <Text>(); Text rng = characterInfoPanel.transform.Find("RNGText").gameObject.GetComponent <Text>(); type.text = character.type; hp.text = character.hp + " / " + character.mhp; atk.text = character.atk.ToString(); def.text = character.def.ToString(); mgk.text = character.mgk.ToString(); wil.text = character.wil.ToString(); spd.text = character.spd.ToString(); rng.text = character.rng.ToString(); } else if (dBuilding != null) { characterInfoPanel.SetActive(true); Text type = characterInfoPanel.transform.Find("TypeText").gameObject.GetComponent <Text>(); Text hp = characterInfoPanel.transform.Find("HPText").gameObject.GetComponent <Text>(); Text atk = characterInfoPanel.transform.Find("ATKText").gameObject.GetComponent <Text>(); Text def = characterInfoPanel.transform.Find("DEFText").gameObject.GetComponent <Text>(); Text mgk = characterInfoPanel.transform.Find("MGKText").gameObject.GetComponent <Text>(); Text wil = characterInfoPanel.transform.Find("WILText").gameObject.GetComponent <Text>(); Text spd = characterInfoPanel.transform.Find("SPDText").gameObject.GetComponent <Text>(); Text rng = characterInfoPanel.transform.Find("RNGText").gameObject.GetComponent <Text>(); type.text = dBuilding.type; hp.text = dBuilding.hp + " / " + dBuilding.mhp; atk.text = dBuilding.atk.ToString(); def.text = dBuilding.def.ToString(); mgk.text = dBuilding.mgk.ToString(); wil.text = "---"; spd.text = dBuilding.spd.ToString(); rng.text = dBuilding.rng.ToString(); } else if (uBuilding != null) { uBuildingInfoPanel.SetActive(true); Text type = uBuildingInfoPanel.transform.Find("TypeText").gameObject.GetComponent <Text>(); Text hp = uBuildingInfoPanel.transform.Find("HPText").gameObject.GetComponent <Text>(); Text def = uBuildingInfoPanel.transform.Find("DEFText").gameObject.GetComponent <Text>(); Text wood = uBuildingInfoPanel.transform.Find("WoodText").gameObject.GetComponent <Text>(); Text stone = uBuildingInfoPanel.transform.Find("StoneText").gameObject.GetComponent <Text>(); Text vil = uBuildingInfoPanel.transform.Find("VilText").gameObject.GetComponent <Text>(); Text food = uBuildingInfoPanel.transform.Find("FoodText").gameObject.GetComponent <Text>(); type.text = uBuilding.type; hp.text = uBuilding.hp + " / " + uBuilding.mhp; def.text = uBuilding.def.ToString(); wood.text = uBuilding.currentWood + " / " + uBuilding.woodStorage; stone.text = uBuilding.currentStone + " / " + uBuilding.stoneStorage; vil.text = uBuilding.currentVillagers + " / " + uBuilding.villagerStorage; food.text = uBuilding.currentFood + " / " + uBuilding.foodStorage; } }