Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do you make enemies multiply?

Discussion in '2D' started by SpeedyArtGames101, Mar 3, 2021.

  1. SpeedyArtGames101

    SpeedyArtGames101

    Joined:
    Feb 4, 2021
    Posts:
    4
    Hello! I'm new to Unity and have NO idea how to do C#. So I've been using tutorials.

    I am working on a 2D platformer. Only one problem.

    The idea i have is that every time you die and the level resets, the enemies multiply. But I don't know how.

    This is the tutorial I'm using, if it is of any help - https://gamedevacademy.org/how-to-build-a-complete-2d-platformer-in-unity/
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,452
    So basically, you will want to Instantiate the enemies at Start when the level begins, even for the very first time without any player deaths. You will need a death counter per level, so some Int variable. Then, you will also need an enemy counter Int variable. Lets say you first run the game, deathCounter is = to 0 and enemyCount is = 2, to keep things simple. If the player dies, increase deathCounter by one, using deathCounter++. Then, when you spawn the enemies, you have some sort of conditional statement that determines what the enemyCount should be based on the deathCounter. if deathCounter = 0, enemyCount = 2. If deathCounter = 1, enemyCount = 4, and so on.

    However, I don't recommend doubling every single time because after 4 or 5 deaths, you are talking about 32, 64 ,etc. enemies and if the player has already died 4 or 5 times with 16 enemies, what makes you think they can beat it with 32, 64 or 128? So you probably want to control that more manually or do a percentage and round up when you have deaths past 3 or 4, like enemyCount = enemyCount * 1.25;

    Anyways, I know you are brand new to Unity and C# but this is actually a good exercise for you as the thing you are trying to achieve will teach you about: Arrays or Lists, Instantiation, and Loops.

    You will also need SpawnPoints which can be chosen randomly at Start as well so the enemies dont just spawn on top of each other.

    Try looking up in Google or YouTube:
    1. Spawn enemies randomly 2D
    -This should get you a good foundation depending on the tutorial you get
    2. Looping through arrays
    -If this isn't covered in the above search, you will want this to select the spawn points.

    Hope this helps, this should be a starting off point
     
  3. SpeedyArtGames101

    SpeedyArtGames101

    Joined:
    Feb 4, 2021
    Posts:
    4
    Thanks