Whats up guys , I’m new to Unity and this is my first game so forgive my stupid question , I want the enemy to spawn at random time between 1-5 seconds but when I applied the script inside the game , the game is spammed with enemies and it continuously nonstop spawning enemies !
I put the script and a a screenshot to understand whats the problem exactly , Thanks for your time
using UnityEngine;
using System.Collections;
public class Game_Control : MonoBehaviour {
private bool Spawn1=true;
public GameObject Spearman;
private float STimer;
void Start () {
STimer = Random.Range(1f,5f);
}
void Update () {
if (Spawn1 = true) {
Instantiate (Spearman, transform.position, transform.rotation);
StartCoroutine (Timer ());
}
}
IEnumerator Timer(){
Spawn1 = false;
yield return new WaitForSeconds (STimer);
Spawn1=true;
}
}