Problem with instantiate and destroy multiple objects
Guys, I did the following code that instantiates 50 objects simultaneously and after 1 second destroys all of them and it works, but the instantiates the game gives a little "locked", probably because of the loop during instantiation. How could I do this without this absurd drop fps, optimizing the code?
Also, how do I instantiate objects scattered on the player's field of view? (First Person) (Does not work as it is in the code)
var teste :GameObject[];
function Start () {
teste = new GameObject[50];
}
if(Raio.RaioCaiu==true)
{
for(sentinela=0;sentinela<25;sentinela++)
{
teste[sentinela]=Instantiate(prefab, new Vector3(Jogador.PosicaoJogador.x+Random.Range(0, 180), Jogador.PosicaoJogador.y, Jogador.Frente.z), Quaternion.identity);
teste[25+sentinela]=Instantiate(prefab, new Vector3(Jogador.PosicaoJogador.x-Random.Range(0, 180), Jogador.PosicaoJogador.y, Jogador.PosicaoJogador.z-Random.Range(10, 30)), Quaternion.identity);
}
}
else
{
for(sentinela=0;sentinela<50;sentinela++)
Destroy(teste[sentinela], 1);
}
Comment
Your answer
Follow this Question
Related Questions
Spawn power ups after random amount of time 1 Answer
how to destroy the previously generated prefab so that we can populated with new set of prefabs ? 0 Answers
Instantiate and destroy an object with the same key 1 Answer
Destroying instantiated game objects from prefab when coliding with the ground 1 Answer