private void Stats_update(int Balance, double buildingmod, double popgrowth, int army, CityStats buttonParent) // Updating popgrowth, buildingmod and balance based on button clicked. { if (buttonParent.building_modifier < 100) // To be sure { buttonParent.building_modifier += (float)buildingmod; } buttonParent.population_growth += (float)popgrowth; BalanceController.balance += -Balance; buttonParent.armySize += army; buttonParent.Update_Citystats(); }
/* De 2 collision gameobjects kunnen hier niet, want dan als een 3e partij collide dan worden ze geupdate hier en klopt het gevecht niet meer. * */ void OnTriggerEnter(Collider collision) // When an other prefab army is hit they collide, based on wether it is an enemy or ally it responds accordingly. { if (collision.gameObject.CompareTag("Town")) { ArmyStats myArmyStats = transform.GetComponent <ArmyStats>(); CityStats cityStats = collision.GetComponent <CityStats>(); if (myArmyStats.playerNumber == cityStats.playerNumber && !myArmyStats.justSpawned) // Own city collision { cityStats.armySize += myArmyStats.armySize; cityStats.Update_Citystats(); Destroy(myArmyStats.gameObject); } else // TODO enemy city collision { } } else if (collision.gameObject.CompareTag("Army")) // Collision between armies { ArmyStats myArmyStats = transform.GetComponent <ArmyStats>(); ArmyStats enemyArmyStats = collision.GetComponent <ArmyStats>(); if (enemyArmyStats.playerNumber == myArmyStats.playerNumber) // Own Team collision { // spawnNumber < spawnNumber is so that the collision only gets done once, because this method is being invoked on both objects if (enemyArmyStats.spawnNumber < myArmyStats.spawnNumber && !myArmyStats.inBattle && !enemyArmyStats.inBattle) { OwnTeamCollision(collision); } else if (!enemyArmyStats.inBattle && myArmyStats.inBattle) // If one of the 2 is in battle { myArmyStats.armySize += enemyArmyStats.armySize; Destroy(enemyArmyStats.gameObject); } } else // Enemy Team collision { if (enemyArmyStats.spawnNumber < myArmyStats.spawnNumber && !myArmyStats.inBattle && !enemyArmyStats.inBattle) { EnemyTeamCollision(collision); } else if (!enemyArmyStats.inBattle && myArmyStats.inBattle) { myArmyStats.inBattleWith.GetComponent <ArmyStats>().armySize += enemyArmyStats.armySize; Destroy(enemyArmyStats.gameObject); } } } }
IEnumerator InstantiateArmy(CityStats buttonParent) // Instantiates an army { bool playerClicked = false; // Only instantiate when a player clickes to move it immediately Vector3 playerClickedTarget = Vector3.zero; float armysize = buttonParent.armySize; buttonParent.armySize = 0; // The city where the army spawned from now has 0 armies buttonParent.Update_Citystats(); while (!playerClicked) // Waits untill the player clicks before instantiating unit { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (Input.GetMouseButtonDown(1)) { playerClicked = true; playerClickedTarget = new Vector3(hit.point.x, 0f, hit.point.z); } } yield return(null); } // Make a new army GameObject newArmy = Instantiate(army, buttonParent.transform.position, Quaternion.identity); ArmyStats newArmyStats = newArmy.GetComponent <ArmyStats>(); newArmyStats.justSpawned = true; // So that it doesnt collide with the town immediately, used in Collide armies to not collide with a town newArmy.transform.parent = GameObject.Find("_Dynamic").transform; // Becomes a dynamic object newArmyStats.armySize = armysize; newArmyStats.isSelected = true; // The army spawned is selected newArmyStats.spawnNumber = StaticLibrary.spawnArmyCounter; newArmyStats.playerNumber = buttonParent.playerNumber; newArmy.GetComponent <MoveArmies>().target = playerClickedTarget; newArmy.GetComponent <MoveArmies>().StartRoutine(); StaticLibrary.DeselectTown(); StaticLibrary.spawnArmyCounter++; playerClicked = false; yield return(new WaitForSeconds(0.5f)); // So that it doesnt collide with the town immediately newArmyStats.justSpawned = false; }