Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Enemy Spawner with conditions

Discussion in 'Scripting' started by Shimuni, May 25, 2020.

  1. Shimuni

    Shimuni

    Joined:
    Sep 14, 2018
    Posts:
    8
    Waves of enemys cross the level from left to right or right to left. Sometimes, enemys have hostages (Characters) between them. Every hostage is preceded and followed by at least one enemy. Waves always have two or more Enemy and exactly one hostage

    any idear how i can achieve that?
     
    Last edited: May 25, 2020
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    There are plenty of ways to achieve it. To make sure a certain amount of things spawn over the duration of a level, you could for example increase the spawn chance for them over the duration of the level that has passed (such that it reaches 100% before the wave ended), and stop spawning once some amount of spawns has been reached.
    To make specific groups spawn, you could either do this through script as well, or predefine these groups through prefabs, which you can then spawn as if they were one enemy.

    There is a gazillion ways to achieve what you want. You could also just hardcode every level. Which approach to chose highly depends on your specific needs.
     
    leftshoe18 likes this.
  3. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    ... but what interest me: is a Ladybug an enemy?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    cso, you are getting pretty philosophical here... :)
     
  5. leftshoe18

    leftshoe18

    Joined:
    Jul 29, 2017
    Posts:
    61
    I was making a wave shooter prototype a while back and what I did was set up a "Spawn Data" class which contained the prefab, max number to spawn, etc. for each enemy that could spawn in a given level. You could easily do something similar and check to make sure the max number hasn't been spawned (in the case of your hostage, limit it to just one spawn per wave).