// Update is called once per frame void Update() { armedCivilianTimer += Time.deltaTime; spawnTime += Time.deltaTime; if (spawnTime >= 60.0f / (unitsPerMinute + randomNum) && civManager.NumCivilians() < civManager.totalCiviliansAllowed) { randomNum = Random.value * 2.0f - 1.0f; spawnTime = 0.0f; Vector3 spawnPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z + 5.0f); float armedCivilianSpawnChance = armedCivilianTimer / 30.0f / 100.0f; if (Random.value < armedCivilianSpawnChance) { GameObject instance = Instantiate( armedUnit, spawnPosition, unit.transform.rotation) as GameObject; } else { GameObject instance = Instantiate( unit, spawnPosition, unit.transform.rotation) as GameObject; } civManager.AddCivilian(); } }
void OnGUI() { GUI.Box(new Rect(10, 10, 100, 20), unitManager.NumUnits() + "/" + unitManager.numUnitsAllowed); GUI.Box(new Rect(10, 35, 100, 20), civManager.NumCivilians() + "/" + civManager.totalCiviliansAllowed); if (unitManager.getNumSelectedUnits() == 1) { GameObject unit = unitManager.GetSelectedUnits()[0]; if (unit != null) { if (unit.name.Contains("Friendly_Civilian")) { UnitHealth unitHealth = unit.GetComponent <UnitHealth>(); MeleeAttackUnitsInRange unitDamage = unit.GetComponent <MeleeAttackUnitsInRange>(); GUI.Box(new Rect(Screen.width / 8.0f, 17.0f * Screen.height / 20.0f, Screen.width / 4.0f, Screen.height / 15.0f), "Health: " + unitHealth.curHealth); GUI.Box(new Rect(Screen.width / 8.0f, 18.5f * Screen.height / 20.0f, Screen.width / 4.0f, Screen.height / 15.0f), "Damage: " + unitDamage.meleeDamage); } } } }