- Home /
Problem is not reproducible or outdated
invokerepeating stops suddenly
so im using the code below to generate mobs. for some reason, when the original prefab gets destroyed, the codes stops creating duplicates as well.
i dont know the reason why it stops when it shouldnt
note: i used it earlier and it works fine, i just used it under a new prefab and new spawn points, so i copied it to a new js script aswell.
#pragma strict
var spawnTrgts : GameObject[];
var newTarget : Transform;
function Start () { //initialize spawning points array
spawnTrgts = GameObject.FindGameObjectsWithTag("sqspawn");
// Debug.Log(spawnTrgts.Length);
}
// Starting in 0.5 seconds, a projectile will be launched every 0.3 seconds
InvokeRepeating("LaunchProjectile", 2, 3);
function LaunchProjectile () {
var spawnPos = spawnTrgts[(Random.Range(0, spawnTrgts.Length))].transform.position; //randomly return position of a spawn point
Instantiate(newTarget, spawnPos, Quaternion.identity);
// Debug.Log(spawnPos);
}
never$$anonymous$$d got it, looks like i just added the prefab from the hierchy and not the assets.
Follow this Question
Related Questions
Instantiate Problem 2 Answers
The variable othertransform of Prefab has not been assigned 2 Answers
Trying to get a shoot function working in unity using instantiate and it isn't working. 1 Answer
Simple Instantiate gameObject problem 3 Answers
Problem with GetComponentinChildren and Instantiate 0 Answers