So we are making this fish game where a bunch of “Enemy fish” will appear on the screen from the right side and the Player fish will have to avoid them by moving up & down. Now the problem occurs when we are trying to spawn those enemy fishes.
void SpawnEnemy(){
Instantiate(prefab, new Vector3(25, Random.Range(1,20), 0), Quaternion.identity);
}
int NextEnemySpawnTime = 0;
int EnemySpawnRate = 5;
void Update(){
if((int)Time.time == NextEnemySpawnTime)){
SpawnEnemy();
NextEnemySpawnTime = (int)Time.time + EnemySpawnRate;
}
}
The idea was to create enemy fish every five seconds, but when we run this a whole bunch of cubes (enemy fishes) floods the screen. How can we make the Update function to call SpawnEnemy() function exactly every five seconds? We’re bunch of newbies, any help/suggestion is appreciated.