Click here to Skip to main content
13,633,851 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 11 Oct 2017
Licenced CPOL

Day 24 of 100 Days of VR: Creating Waves for Spawning System in Unity

, 11 Oct 2017
Rate this:
Please Sign up or sign in to vote.
How to create waves for spawning system in Unity

Today in Day 24, we’re going to resume working on our EnemySpawner.

Yesterday, we laid the groundwork that allows us to spawn enemies, however, we haven’t implemented finishing a wave yet.

As a result, we only spawn our 5 enemies and then nothing happens after we defeat them.

Today, we’re going to make some changes so that we can move on to the next wave and then win the game.

On a different note, after reading some other articles, I decided that I like their formatting, so I’m going to organize my articles the same way.

Step 1: Create a SpawnManager Tag for our SpawnManager

The first thing that we need to do is to set a Tag for our SpawnManager.

We need to do this, because later in EnemyHealth, when our enemy dies, we want to be able to reference our SpawnManager.

Select our SpawnManager game object and then under tag, select Add Tag… and create a new Tag called SpawnManager. Then go back to our game object and attach the tag like above.

Step 2: Change EnemyHealth.cs to Use Our SpawnManager

For our EnemyHealth script, we need access to our SpawnManager script so we can call EnemyDefeated(), which we implemented yesterday.

Here’s our change:

using UnityEngine;

public class EnemyHealth : MonoBehaviour
    public float Health = 100;
    public AudioClip[] HitSfxClips;
    public float HitSoundDelay = 0.5f;

    private SpawnManager _spawnManager;
    private Animator _animator;
    private AudioSource _audioSource;
    private float _hitTime;

    void Start()
        _spawnManager = GameObject.FindGameObjectWithTag("SpawnManager").GetComponent<SpawnManager>();
        _animator = GetComponent<Animator>();
        _hitTime = 0f;

    void Update()
        _hitTime += Time.deltaTime;
    public void TakeDamage(float damage)
        if (Health <= 0) { return; } Health -= damage; if (_hitTime > HitSoundDelay)
            _hitTime = 0;

        if (Health <= 0)

    private void SetupSound()
        _audioSource = gameObject.AddComponent<AudioSource>();
        _audioSource.volume = 0.2f;

    private void PlayRandomHit()
        int index = Random.Range(0, HitSfxClips.Length);
        _audioSource.clip = HitSfxClips[index];

    private void Death()

Here are the changes we made:

  1. We get access to our SpawnManager: _spawnManager, which we’ll notify when an enemy dies.
  2. In Start(), we get _spawnManager by finding our SpawnManager game object from its tag and then getting the SpawnManager script attached to it.
  3. In Death() when the knight is defeated, we’ll call EnemyDefeated(), which will decrement our enemy count and call the next wave if all enemies are defeated.

Now when we play the game, after we defeat our first 5 enemies, our next 10 will show up.

Look at the fate of all those who opposed us!


Today has been a relatively busy day, so today’s progress has been relatively short. However, we’re almost done with our Spawning System.

Tomorrow, we’re going to create a player victory state and then fully complete our player spawning feature to our simple FPS!

I’ll see you all tomorrow!

Day 23 | 100 Days of VR | Day 25


The post Day 24 of 100 Days of VR: Creating Waves for Spawning System in Unity appeared first on Coding Chronicles.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02-2016 | 2.8.180712.1 | Last Updated 12 Oct 2017
Article Copyright 2017 by IAmJoshChang
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid