WTF is going on

//not working

public var struc : Transform [];
public var units : Transform [];

var posi = 25;
for (var curb : Transform in struc) {
posi += 25;
if (GUI.Button (Rect (75,posi,75,25), curb.name)) {
		struc.Add(curb);
	}
}



//Working


var pos = 25;
for (var curu : Transform in units) {
pos += 25;
if (GUI.Button (Rect (0,pos,75,25), curu.name)) {
		orders.Add(curu);
	}
}

ok so both of these snipets are ment to do the same thing but with a diferent array howether i get this on the second one

Add’ is not a member of ‘UnityEngine.Transform’.

and i carnt spot any diferance :frowning:

You can’t “Add” items to a built-in array. You’d have to use a List instead.

// Add this line to the top of the file:
import System.Collections.Generic;

// And use Lists instead of Arrays:
public var struc : List.<Transform>;
public var units : List.<Transform>;

// Rest of code...

Well, not to state the obvious, but Add() is not a member of UnityEngine.Transform:wink:

Here is a nice explanation of different arrays and lists you can use: Which kind of array should I use? In this case I’d go for the JavaScript Array, if you’re not worried about speed.

And are you sure the latter one is working? Because they both seem wrong…

Built in arrays don’t have .Add, UnityEngine.Array does, as do List and ArrayList

Your best bet is to use List really:

import System.Collections.Generic;

public var struc : List.<Transform>;

Then you can use struc.Add(whatever)

Add is a member of the List class, not of Array. I.e. you can’t call Add on an array. I assume orders is a List? An array is of a static size, so you have to explicitly set the elements at each index, often in a for-loop.

I think you need to create the length of the array and or use struc.(transform)

http://unity3d.com/support/documentation/ScriptReference/Array.html