public void Spawn() { if (!GameplayController.CanUpdate() || cooling || resources.current < 10) { return; } //pick a spawner int idx = Random.Range(0, 3); Vector3 spawnPos = spawners [idx].position; GameObject newUnit = Instantiate(unitPref) as GameObject; newUnit.transform.SetParent(unitsContainer); newUnit.transform.position = spawnPos; newUnit.transform.localScale = Vector3.one; //if autopilot on, pick an order if (autoPilot) { int order = resources.current <= 15 ? UnitController.COLLECT : Random.Range(0, 3); newUnit.SendMessage("SetOrder", order); } cooling = true; resources.current -= 10; }
void ExtractResource(GameObject tower) { if (GameplayController.CanUpdate() && health > 0) { tower.SendMessage("ModifyResources", 2); } }
void ModifyHealth(float val) { if (GameplayController.CanUpdate()) { health.current += val; health.current = Mathf.Clamp(health.current, 0, health.max); } }
void ModifyResources(float val) { if (GameplayController.CanUpdate()) { resources.current += val; resources.current = Mathf.Clamp(resources.current, 0, resources.max); } }
// Update is called once per frame void Update() { if (!GameplayController.CanUpdate()) { return; } resources.current += resourcesSpeed * Time.deltaTime; UpdateCooldown(); AutoSpawn(); }
void ModifyHealth(float val) { if (GameplayController.CanUpdate()) { health += val; health = Mathf.Clamp(health, 0, 5); if (health <= 0) { state = UnitState.dead; } } }
void ModifyHealth(float val) { if (GameplayController.CanUpdate()) { health += val; health = Mathf.Clamp(health, 0, 15); if (health <= 0) { health = 0; timer = 0; } } }
// Update is called once per frame void Update() { if (!GameplayController.CanUpdate()) { return; } audioSrc.maxDistance = originalSoundMaxDistance * GameBoard.scale; //check for near enemies while target is the main target if (target == mainTarget) { target = CheckForEnemies(); } //enemy killed look for new target /*if (target == null && (order == DEFEND || order == ATTACK)) { * state = UnitState.idle; * target = CheckForEnemies (); * }*/ //resource is empty, look for a new one if (curResource != null && curResource.health <= 0 && order == COLLECT) { state = UnitState.idle; target = mainTarget = GetClosestResource(); } //no targets at all, go back to main target and idle if (target == null) { target = mainTarget; state = UnitState.idle; } switch (state) { case UnitState.idle: Idle(); break; case UnitState.walk: Walk(); break; case UnitState.attack: Attack(); break; case UnitState.dead: Die(); break; default: break; } }
// Update is called once per frame void Update() { if (health <= 0 && GameplayController.CanUpdate()) { rock.SetActive(false); destroyed.SetActive(true); timer += Time.deltaTime; if (timer >= 15) { rock.SetActive(true); destroyed.SetActive(false); timer = 0; health = 15; } } }