- Home /
Question by
armandas2005 · Apr 14, 2021 at 11:12 AM ·
spawnchecknumber
Check number
i made a wave spawner script. I want it to spawn an boss enemy every 10th wave but how can i check if the 10th wave has passed?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaveSpawner : MonoBehaviour
{
public GameObject[] enemys;
public GameObject[] bosEnemy;
public float timeBetweenWaves;
public int WaveCount;
public int enemyCount;
public int spawnedEnemys;
int randomInt;
void Update()
{
if(enemyCount == 0)
{
Invoke("SpawnRandom", timeBetweenWaves);
WaveCount++;
}
}
void SpawnRandom()
{
for (int i = 0; i < spawnedEnemys; i++)
{
randomInt = Random.Range(0, enemys.Length);
Instantiate(enemys[randomInt], transform.position, Quaternion.identity);
enemyCount++;
}
//every 10th wave it should spawn an bosEnemy
}
}
Comment
Best Answer
Answer by UnityM0nk3y · Apr 14, 2021 at 11:21 AM
Use a integer to count the waves, spawn, then reset it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaveSpawner : MonoBehaviour
{
public GameObject[] enemys;
public GameObject[] bosEnemy;
public float timeBetweenWaves;
public int WaveCount; //could use this, but not sure if you want to spawn only a boss/boss + wave
public int WaveCountBoss;
public int enemyCount;
public int spawnedEnemys;
int randomInt;
void Update()
{
if(enemyCount == 0)
{
Invoke("SpawnRandom", timeBetweenWaves);
WaveCount++;
WaveCountBoss++;
}
}
void SpawnRandom()
{
for (int i = 0; i < spawnedEnemys; i++)
{
randomInt = Random.Range(0, enemys.Length);
Instantiate(enemys[randomInt], transform.position, Quaternion.identity);
enemyCount++;
}
if (WaveCountBoss >= 10)
{
WaveCountBoss = 0;
//spawn boss here
}
//every 10th wave it should spawn an bosEnemy
}
}
Your answer
Follow this Question
Related Questions
Is there a tutorial for an endles-runner in 2 directions? 0 Answers
check if object is destroyed ? 3 Answers
Network - Killing Player, Then Respawn - Issue with RPC 1 Answer
How to set up random spawnpoints? 1 Answer
Simple array an spawning question 6 Answers