Question by
swapnildave3 · Mar 14, 2021 at 05:59 AM ·
triggerspawnspawn points
How to add trigger system in my enemy spawner script/
public class spawner : MonoBehaviour
{
private int waveNumaber = 0;
public int enemySpawnAmount = 0;
public int enemykilled = 0;
public GameObject[] spawners;
public GameObject enemy;
private void Start()
{
spawners = new GameObject[2];
for (int i =0; i < spawners.Length; i++)
{
spawners[i] = transform.GetChild(i).gameObject;
}
Startwave();
}
private void Update()
{
if(Input.GetKeyDown(KeyCode.T))
{
SpawnEnemy();
}
if (enemykilled >= enemySpawnAmount)
{
Nextewave();
}
}
private void SpawnEnemy()
{
int spawnerID = Random.Range(0, spawners.Length);
Instantiate(enemy, spawners[spawnerID].transform.position, spawners[spawnerID].transform.rotation);
}
private void Startwave()
{
waveNumaber = 1;
enemySpawnAmount = 3;
enemykilled = 0;
for(int i = 0; i < enemySpawnAmount; i++)
{
SpawnEnemy();
}
}
public void Nextewave()
{
waveNumaber++;
enemySpawnAmount += 2;
enemykilled = 0;
for (int i = 0; i < enemySpawnAmount; i++)
{
SpawnEnemy();
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Spawn object doesn't trigger an object to move,Problem with trigger and spawned objects 0 Answers
I need help with my spawning system(SOLVED) 1 Answer
Spawning with trigger 2 Answers
My Code freezes Unity - not sure what to do... 1 Answer
Flag capture with spawning and destroying gameObject 0 Answers