private void GetNextTarget() { if (tower.enemies.Count > 0) { currentTarget = tower.enemies[0]; } }
private void UnSubscribeEnemy(EnemyHealthBehaviour health) { if (enemies.Contains(health)) { enemies.Remove(health); } }
private void SubscribeEnemy(EnemyHealthBehaviour health) { if (!enemies.Contains(health)) { enemies.Add(health); } }
private void Awake() { enemyHealthBehaviour = GetComponent <EnemyHealthBehaviour>(); addScoreBehaviour = GetComponent <AddScoreBehaviour>(); scoreManager = FindObjectOfType <ScoreManager>(); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag.Equals("Enemy")) { EnemyHealthBehaviour enemyTakeDamage = collision.GetComponent <EnemyHealthBehaviour>(); SubscribeEnemy(enemyTakeDamage); } }
private void SpawnMonsters(RoomController roomController) { if (roomController.RoomType == RoomType.COMMON) { EnemyHealthBehaviour enemyToSpawn = Instantiate( _enemiesPrefabs[Random.Range(0, _enemiesPrefabs.Length)], transform.position, Quaternion.identity); roomController.Enemies.Add(enemyToSpawn); _roomController.OnRoomEntered -= SpawnMonsters; } }
private void OnTriggerExit2D(Collider2D collision) { if (collision.gameObject.tag.Equals("Enemy")) { EnemyHealthBehaviour enemyTakeDamage = collision.GetComponent <EnemyHealthBehaviour>(); UnSubscribeEnemy(enemyTakeDamage); if (EnemyOutOfRange != null) { EnemyOutOfRange.Invoke(); } } }
private void RemoveEnemy(EnemyHealthBehaviour enemy) { if (_isClosed == true) { Transform enemyTransform = enemy.transform; Enemies.Remove(enemy); if (Enemies.Count == 0 && _isClear == false) { _isClear = true; OnLastEnemyKilled?.Invoke(enemyTransform); OnRoomCleared?.Invoke(this); } } }