private void SpawnBoss() { GameObject bossGO = Instantiate(_bossPrefab, _bossSpawnPosition, Quaternion.identity); BossShotController bossController = bossGO.GetComponent <BossShotController>(); bossController.SetBossBattle(this); _bossHealthShield = bossGO.GetComponent <EnemyHealthShield>(); _bossHealthShield.OnDamaged += BossBattle_OnDamaged; _bossHealthShield.OnDeath += BossBattle_OnDeath; }
private void RemoveHealthShieldBars(EnemyHealthShield healthShield) { if (enemiesHealthShieldBars.ContainsKey(healthShield)) { if (enemiesHealthShieldBars[healthShield] != null) { Destroy(enemiesHealthShieldBars[healthShield].gameObject); } enemiesHealthShieldBars.Remove(healthShield); } }
private void SpawnEnemy() { int aliveCount = 0; foreach (GameObject enemySpawnedGO in _enemySpawnList) { if (enemySpawnedGO != null) { EnemyHealthShield enemySpawned = enemySpawnedGO.GetComponent <EnemyHealthShield>(); if (enemySpawned.isAlive) { // Enemy alive aliveCount++; if (aliveCount >= maxEnemiesAlive) { // Don't spawn more enemies return; } } } } GameObject enemySpawn = null; switch (_currentStage) { case Stage.Stage_1: enemySpawn = _enemyStage1Prefab; break; case Stage.Stage_2: enemySpawn = _enemyStage2Prefab; break; case Stage.Stage_3: enemySpawn = _enemyStage3Prefab; break; case Stage.Stage_4: enemySpawn = _enemyStage4Prefab; break; } Vector3 spawnPosition = _spawnPositionList[UnityEngine.Random.Range(0, _spawnPositionList.Count - 1)]; if (enemySpawn != null) { GameObject newEnemy = Instantiate(enemySpawn, spawnPosition, Quaternion.identity); _enemySpawnList.Add(newEnemy); } }
public void SetHealthShield(EnemyHealthShield healthShield) { _healthShield = healthShield; _healthShield.OnHealthPctChanged += HandleHealthChanged; _healthShield.OnShieldPctChanged += HandleShieldChanged; _healthBarImage.fillAmount = healthShield.GetHealthPct(); _shieldBarImage.fillAmount = healthShield.GetShieldPct(); if (!healthShield.HasShield()) { _shieldBackgroundImage.gameObject.SetActive(false); } }
private void DestroyAllEnemies() { foreach (GameObject enemySpawn in _enemySpawnList) { if (enemySpawn != null) { EnemyHealthShield enemyHealthShield = enemySpawn.GetComponent <EnemyHealthShield>(); if (enemyHealthShield != null && enemyHealthShield.isAlive) { enemyHealthShield.Die(); } } } }
private void AddHealthShieldBars(EnemyHealthShield healthShield) { if (healthShield.IsBoss) { EnemyHealthShieldBarsUI healthShieldBars = Instantiate(_bossHealthShieldBarsPrefab, transform); healthShieldBars.SetHealthShield(healthShield); enemiesHealthShieldBars.Add(healthShield, healthShieldBars); } else { EnemyHealthShieldBarsUI healthShieldBars = Instantiate(_healthShieldBarsPrefab, transform); healthShieldBars.SetHealthShield(healthShield); enemiesHealthShieldBars.Add(healthShield, healthShieldBars); } }
private void Start() { _enemyHealthShield = GetComponent <EnemyHealthShield>(); _enemyHealthShield.OnDeath += EnemyHealthShield_OnEnemyDie; }