accessing array using [] method

If I create an array using

var arr = new Array (“Hello”, “World”);

I can easily remove an element using

arr.RemoveAt(1);

Now, if I create the array this way:

var objs : GameObject[ ];

and add the elements in the interface, how do I get acces to them?

objs.RemoveAt(1); doesn’t work. It’s probably very stupid. I searched the doc and the forum but I couldn’t find an example.

EDIT: I need to know how to make RemoveAt working with the second method of arrays.

Well, since your array is of gameObjects, just do this:

var holder : GameObject = arrayName[0];

That’ll get you the position at the first spot in the array. 1 is second spot, 2 is third spot, etc…

So, to summarize, any variable of type GameObject can just = arrayName[integer];

Actually I didn’t explain de problem properly.

What I need is how do you use the removeAt when using the var objs : GameObject[ ] method instead of the var arr = new Array (“Hello”, “World”)

Well, you don’t as per the Array entry in the scripting reference which states:

Builtin arrays (native .NET arrays), are extremely fast and efficient but they can not be resized.

If you need to remove an entry then you’ll have to convert the built-in array to a standard array, modify it by removing elements, then convert it back to a built-in array. Check the Array page in the script reference as it shows you how to do that.

Rock on! :slight_smile:

I read about that in the doc, I just didn’t know that the array in the interface was a .Net one.

Thanks!

-R

The .Net array is documented here:

There is actually a Resize() method, though since the array is fixed-length, that will internally copy the array into a new resized one. If you only need to resize the array seldom, that’s not a big issue.

They may have solved your problem, but i would also like to contribute :slight_smile:

I am pretty sure you can also do this

var theoneuwanttoremove : GameObject
var waste : GameObject;

gos[0] = theoneuwanttoremove;
gos[0] = waste;