protected virtual void Attack() { if (!canAttack) { attackTimer += Time.deltaTime; if (attackTimer >= attackCooldown) { canAttack = true; attackTimer = 0f; } } if (target == null && monsters.Count > 0) { target = monsters.Dequeue(); } if (target != null) { if (canAttack) { Shoot(); canAttack = false; } } else if (monsters.Count > 0) { target = monsters.Dequeue(); } if (target != null && !target.isActive) { target = null; } }
public void OnTriggerExit2D(Collider2D collision) { if (collision.tag == "Monster") { target = null; } }
public void RemoveMonster(UnityMonster monster) { activeMonsters.Remove(monster); if (!IsWaveActive) { waveBtn.SetActive(true); controlsBtn.SetActive(true); } }
public void Awake() { Monsters = GetComponent <UnityMonster>(); Pool = GetComponent <ObjectPool>(); Currency = 5; lives = 3; livesText.text = string.Format("Lives: <color=lime>{0}</color>", lives); panel.SetActive(false); controlsPanel.SetActive(false); isPanelActive = false; }
//Coroutines private IEnumerator SpawnWave() { UnityGridManager.Instance.GeneratePath(); for (int i = 0; i < wave; i++) { int monsterIndex = Random.Range(0, 4); string type = string.Empty; switch (monsterIndex) { case 0: type = "BlueMonster"; break; case 1: type = "YellowMonster"; break; case 2: type = "MagentaMonster"; break; case 3: type = "GreenMonster"; break; } UnityMonster monster = Pool.GetObject(type).GetComponent <UnityMonster>(); monster.Spawn(monsterHealth); activeMonsters.Add(monster); if (wave % 3 == 0) { monsterHealth += 5; } yield return(new WaitForSeconds(1.5f)); } }
public void Initialize(UnityArcher parent) { this.parent = parent; this.target = parent.Target; }