- Home /
This question was
closed Oct 21, 2015 at 09:46 AM by
ar4ta for the following reason:
The question is answered, right answer was accepted
Question by
ar4ta · Oct 21, 2015 at 09:34 AM ·
instantiatespawncloneinvokerepeating
How to stop instantiate spawn ?
Anybody know how can i stop cloning object when the game finish / times up ? I'am using InvokeRepeating to clone object, this is the script :
using UnityEngine;
using System.Collections;
public class SpawnerScript : MonoBehaviour {
public float spawnTime = 5f;
public float spawnDelay = 3f;
public GameObject[] myPrefab;
void Start () {
InvokeRepeating ("Spawn", spawnDelay, spawnTime);
}
void Spawn() {
// Instantiate a random prefab
int notPrefabIndex = Random.Range (0, myPrefab.Length);
Instantiate (myPrefab [notPrefabIndex], transform.position, transform.rotation);
}
}
Thanks before..
Comment
Answer by allenallenallen · Oct 21, 2015 at 09:35 AM
Simple. Look at the API: http://docs.unity3d.com/ScriptReference/MonoBehaviour.CancelInvoke.html
if (/*Game over condition met*/){
CancelInvoke("Spawn");
}