|
The problem isn't the array actually, the problem is finding a solution to my troubles really. Let me try and explain what I'm trying to do. First, I'm setting variables. I also make a built-in array for gameobjects. and in the start function I add these gameobjects to the array. Elsewhere I'm instantiating each of these by use of random number, This function takes a random number, instantiates the object and then what I would like it to do after that is, remove that same object from the array. The problem is, which I just found out a minute ago- you cannot remove objects from a built-in array because these arrays have a fixed size. I have looked around and I found another method in which you could add gameobjects to an arraylist, the problem with that for me was that the length of the array would always came back null. Is that normal? Can anyone possibly give me some insight? Thank you.
(comments are locked)
|
|
This is what lists are for. They are type safe, but at the same time, they are resizable. There are a couple different types of lists, but in your case, the basic list should work well: then you shouldn't have to change how your instantiate code works. You can access lists the same way as arrays with the index i.e. And its easy to remove items: as described here. wonderful, thank you !
Sep 21 '11 at 12:38 AM
feneq
(comments are locked)
|
|
Yes, there is a distinct difference between built-in arrays such as GameObject[] and Array(). If you want to resize a built-in array, you'll have to handle the removal of the element yourself using a custom method to rebuild the array. Here's code that should do the trick. This is great and works. It's great because something like this did not even occur to me so it will help me down the road when finding solutions to a problem. However, I'm not entirely sure, but I believe the answer posted by Peter G. may be better suited for the task at hand. Thank you sir.
Sep 21 '11 at 12:38 AM
feneq
(comments are locked)
|
