x


Rebuilding an Array

(I am currently using C#)

I have a set of objects (cubes in this case) that I am loading into an array to perform all sorts of functions on. My issue is that I want to be able to delete the cubes, replace them (instance their prefabs into the scene) wherever I want them and then continue running my functions with the new cubes.

I've probably overlooked a simple solution (as is commonly the case with these things).

So, what I want to know is how to have it so the scripts don't suddenly run aground when they have no cubes to reference inside the arrays, and how to re-build the content of the arrays once the cubes have been replaced. Can I disable a script and then restart it, re-finding the new cubes?

(just as an addition I am loading the cubes into the array using tags)

cubeArray = GameObject.FindGameObjectsWithTag ("cube");

more ▼

asked Jun 27 '12 at 03:45 PM

Flufflesthepancake gravatar image

Flufflesthepancake
92 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Use a list, and remove each cubes you're destroying, add those you create.

more ▼

answered Jun 27 '12 at 04:00 PM

Berenger gravatar image

Berenger
11.2k 12 19 54

So basically I have to change all my arrays into lists? And change all the methods of doing things into the ones that relate to lists... and... dayum.

Jun 27 '12 at 04:16 PM Flufflesthepancake

Whenever a data structure's size is going to change, go for the list. If you know it will remain constant, arrays are perfectly fine.

Jun 27 '12 at 04:38 PM Berenger
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1396

asked: Jun 27 '12 at 03:45 PM

Seen: 180 times

Last Updated: Jun 27 '12 at 04:38 PM