protected void _spawnNewEnemy(GameObject enemyPrefab, Vector3 position, WaypointComponent startWaypoint) { GameObject instantiatedEnemy = GameObject.Instantiate(enemyPrefab, position, Quaternion.identity, mEnemiesRootTransform); EnemyComponent enemyComponent = instantiatedEnemy.GetComponent <EnemyComponent>(); if (enemyComponent == null) { return; } /// copy shared values into individual fields enemyComponent.mHealth = enemyComponent.mConfigs.mHealth; enemyComponent.mCurrWaypoint = startWaypoint; /// update enemy's UI HealthBarView healthBarView = enemyComponent.GetComponentInChildren <HealthBarView>(); healthBarView.CurrNormalizedHealth = 1.0f; }
protected bool _processSingleBullet(BulletComponent bullet) { EnemyComponent damagedEnemy = bullet.mDamagedEnemy; /// skip the bullet because it didn't hit any enemy if (damagedEnemy == null) { return(false); } HealthBarView healthBarView = damagedEnemy.GetComponentInChildren <HealthBarView>(); float newHealth = Mathf.Max(0.0f, damagedEnemy.mHealth - bullet.mDamage); healthBarView.CurrNormalizedHealth = newHealth / damagedEnemy.mConfigs.mHealth; /// compute normalized health's value damagedEnemy.mHealth = newHealth; /// destroy enemy's view if (damagedEnemy.mHealth < 1e-3f) { DestroyedComponent destroyedComponent = damagedEnemy.GetComponent <DestroyedComponent>(); destroyedComponent.mShouldBeDestroyed = true; /// kill the enemy //GameObject.Destroy(damagedEnemy.gameObject); EventBus.NotifyOnEnemyDestroyed(damagedEnemy.mConfigs.mReward); } /// TODO: return bullet to an object pool of bullets //GameObject.Destroy(bullet.gameObject); DestroyedComponent destroyedBullet = bullet.GetComponent <DestroyedComponent>(); destroyedBullet.mShouldBeDestroyed = true; return(true); }