2D platformer course – Infinite waves with stronger enemies

Updated on December 25, 2018 in [A] Brackeys Courses
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on December 25, 2018

Hi, I am trying to make infinite waves with enemies getting stronger after I have completed all waves. Let’s say I have 5 waves. After I complete the 5 waves, I want to repeat them and make enemies stronger (for example change their max hp from 120 to 130 or increase the enemies count). I have tried to change the maxHealth variable in the SpawnEnemy method of the WaveSpawner.cs file:

 

 
private void SpawnEnemy(Enemy enemy)
{
  Transform sp = spawnPoints[UnityEngine.Random.Range(0, spawnPoints.Length)];
  if (CurrentWave % 5 == 0)
  {
    enemy.stats.maxHealth += 20;
  }
  Instantiate(enemy.transform, sp.position, sp.rotation);
}
 

 

And it works, but it’s actually changing the prefab values in the inspector. So when I restart my game, the enemies start with the max health set at the last wave. For example if I set the starting max health in the inspector to 120, after I play the game and complete 5 waves, the  prefab max health value becomes 140 and I have to change it back to 120 (or reset it).

 

I have tried other various ways to implement this feature, but to no avail. I would be very glad if someone could help me out.
Thanks.

  • Liked by
Reply