- Home /
Changing the spawn rate
Hi, I wanted to know if anyone could help me with this code. I am trying to change the spawn rate through the use of arrays. However, I am having problems the code below makes the planes spawn at the same time and same distance to the level. How do I edit this to make it appear more random?
Thanks.
function Start () { gather_spawners(); }
function Update () { spawn_new_plane(); }
private var spawners = new Array();
var plane : GameObject;
private var spawnDelay : float = 1.0; private var timeToSpawn : float = 0.0;
function spawn_new_plane() { if(Time.time > timeToSpawn) { // Choose a random spawn point (from the spawners array)
var rNum : int = Random.value * spawners.length;
var randomSpawnPoint : Transform = spawners[rNum];
Instantiate(plane, randomSpawnPoint.position, randomSpawnPoint.rotation); timeToSpawn = Time.time + spawnDelay; }
}
function gather_spawners() { var potentialSpawners : Array = GetComponentsInChildren(Transform);
for (var potentialSpawner : Transform in potentialSpawners) {
if(potentialSpawner != transform) {
spawners[spawners.length] = potentialSpawner;
}
}
Debug.Log("SL: " + spawners.length);
You have created 4 topics topics, you haven't sorted your code in none of them, not even mentioning that you have not closed (accepted) any of the given answers developers have given to you.
Readers don't have to waste their time trying to read what code are you showing, just because you couldn't press one button.
Please, take this as a note. Otherwise i just wont accept any of your further questions.