- Home /
Question by
onilson · Dec 11, 2017 at 09:17 PM ·
spawn points
how to limit a trigger frequency?
Sorry for my English because it was written in google translator.
I'm trying to do programming that might limit the spawn of the enemy, but I do not know how to do it.
public GameObject Inimigo;
public float spawnTime;
public Transform[] spawnPoints;
// Use this for initialization
void Start () {
InvokeRepeating ("Spawn", spawnTime, spawnTime);
}
void Update(){
}
// Update is called once per frame
void Spawn () {
if(Vida_Jogador.Vida <= 0f){
return;
}
int spawnPointIndex = UnityEngine.Random.Range (0, spawnPoints.Length);
Instantiate (Inimigo, spawnPoints [spawnPointIndex].position, spawnPoints [spawnPointIndex].rotation);
}
Comment
what if you put the int spawnPointIndex = UnityEngine.Random.Range (0, spawnPoints.Length); line in Start function? seems like in Spawn(), it is generating a new Random.Range as long as it is still in that function. Or in the Update fuction but a limit. Like if InimigoCount > limit to stop spawning. Limit being a public float and InimigoCount an int that gets added to for every instatiated?