Forum begins after the advertisement:


[Part 7] Trouble with Enemy Spawning

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 7] Trouble with Enemy Spawning

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #12676
    Level 11
    Former Patron
    Helpful?
    Up
    0
    ::

    I have 5 round enemies but when round 1 ends it always jumps to round 5 and skips round 2-3-4

    View post on imgur.com
    #12677
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Hi Lê, check out this post. It should help: https://blog.terresquall.com/community/topic/part-6-error-in-enemy-spawner/

    #12681
    Level 11
    Former Patron
    Helpful?
    Up
    0
    ::

    It is not working with me. but I’ve fixed that by adding Boolean

    <code>
    private bool newWave = false;
    int currentWaveQuota = 0;
    
    void Update()
    {
        if (!waveStarted && currentWaveCount < waves.Count && waves[currentWaveCount].waveQuota == currentWaveQuota)
        {
            StartCoroutine(BeginNextWave());
            newWave = true; 
        }
    
        spawnTimer += Time.deltaTime;
    
        //Check if it's time to spawn the next enemy
        if (spawnTimer >= waves[currentWaveCount].spawnInterval)
        {
            spawnTimer = 0f;
            SpawnEnemies();
        }
    }
    
    IEnumerator BeginNextWave()
    {
        yield return new WaitForSeconds(waveInterval);
    
        if (currentWaveCount < waves.Count - 1)
        {
            currentWaveCount++;
            CalculateWaveQuota();
            newWave = false;
        }
    }
    }
    
    void CalculateWaveQuota()
    {
        int currentWaveQuota = 0; => Delete this
    
        foreach (var enemyGroup in waves[currentWaveCount].enemyGroups)
        {
            currentWaveQuota += enemyGroup.enemyCount;
        }
    
        waves[currentWaveCount].waveQuota = currentWaveQuota;
        //Debug.LogWarning(currentWaveQuota);
    }
    </code>
    #12686
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Glad you managed to fix this!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: