Question is off-topic or not relevant
How do I stop enemy from spawning on start?
I am making an enemy spawn script here and it works extremely well except for one little detail. As soon as you hit play, there are already two enemies coming at you (One for each of my two spawners) How do I prevent this from happening, I've tried to work it out with no luck and I'm fairly new here. Thanks :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnScript : MonoBehaviour
{
public GameObject enemy1, enemy2;
public int nextSpawn = 0;
int whatToSpawn;
void Update()
{
Debug.Log(nextSpawn);
if (nextSpawn == 0)
{
whatToSpawn = Random.Range(1, 3);
Debug.Log(whatToSpawn);
switch (whatToSpawn)
{
case 1:
Instantiate(enemy1, transform.position, Quaternion.identity);
break;
case 2:
Instantiate(enemy2, transform.position, Quaternion.identity);
break;
}
nextSpawn = Random.Range(60, 100);
}
else if(nextSpawn > 0)
{
nextSpawn--;
}
}
}
Answer by tormentoarmagedoom · Sep 28, 2019 at 03:18 PM
Hello there!
You should leran about time usage in unity.
You are using Update as a "timer" using frames to count to know when to spawn again...
Really, I strongly recommend 300% to STOP, and spend next 5-10 hours learning about this things (look for them, watch tutorials in youtube, etc...) If you pretend to build a house, firt at least learn to how to make concrete... If not when reaching the roof will see your house is not stable and will fall down.
As I said, stop, and spend next 5-10 hours reading and watching tutorials about all this things (dont be afaraid to dont understand.... for sure at the begining will understand NOTHING, but hour by hour will see you understand a litle bit more, so rewatch that tutorial you didnd understand at the begining :D
Look for this at youtube/google using the word UNITY first:
Time
Time.deltaTime
IEnumerator
Corutines
Countdown
Frames
Update / FixedUpdate / LateUpdate
Usage of methods
Good luck!