- Home /
how can I destroying a spawn object ?
hello ^^ I have created several spawning objects , to fall down from the top of the scene to the bottom, I've created it so there is a time limit of 3 seconds between each spawn. Therefor, I have several rows of the spawning objects . I've programmed it so that when a key is pressed the object explodes , the problem I'm facing is that when a key is pressed the object is destroyed , even the spawning of the object is destroyed :/ how can I have it so that when a key is pressed the first spawn is destroyed , and then when pressed again the second spawn is destroyed
Did you tried using Integer with your spawning order? Everytime Objects oxplodes, Integer increments and if () statement is done to recognize value of that Int ...
I'm sorry I don't quite understand what you mean , I used Integer with the spawn order , I also used different scripts for destroying the objects and spawning , the problem is the objects are being destroyed dependently on one another
Answer by richyrich · Oct 21, 2014 at 04:51 PM
//Create the spawn list
//List<GameObject> spawnList = new List<GameObject>();
//Do your spawing. Set bob equal your spawned game object
//GameObject bob = whatever, etc.
//spawnList.Add(bob);
//When you want to destroy the first item, you just do this:
//spawnList.RemoveAt(0);
//As an example, see the use of simple integers to achieve this result
//To use the next line of code, you would need to place this at the top of your code: using System.Collections.Generic;
List<int> spawnList = new List<int>();
spawnList.Add(5); //this gets deleted first
spawnList.Add(6);
spawnList.Add(7);
spawnList.RemoveAt(0);
Debug.Log("Spawn = " + spawnList[0]);//outputs 'Spawn = 6'
//this might not be the best implementation, but it's something to get you started
Your answer
Follow this Question
Related Questions
Losing references after reloading the scene, even though they exist again. 1 Answer
how to destroy a object only in game and not the prefab 2 Answers
Destroy Istantiated objects after some time (different for each instance) 1 Answer
How Do I Add An Instantiated Object To An Array? 3 Answers
how to "search" for a spawn point 0 Answers