x


Using lists or arrays of transforms in Boo.

I'm pretty sure this is just a syntax problem, but an hour or so on google has not solved my problem. I'm trying to make a weapon selector. I can get it to work with some ugly code that amounts to (pseudocode): If button is clicked If currentweapon == x currentweapon = y

needless to say this would be very ugly to do for a dozen weapons. I want to put them into a list on an array but I can't seem to make it work. I'm declaring these weapons as Transforms and assigning them in the inspector, but how do I stuff them in a list such that I can later instantiate an item in that list? I'm using boo which seems to be woefully underdocumented compared to the other two languages unity supports. Any assistance would be very helpful.

my current attempts (which I commented out each time I tried a different strategy) look like this:

public cannon as Transform 
public minigun as Transform
public rail as Transform
public gauss as Transform
public rockets5 as Transform
public rockets13 as Transform
public missile as Transform
public torp as Transform
#private gunlist as (Transform) = array[of Transform](cannon, minigun, rail, gauss, rockets5, rockets13, missile, torp)
#private gunlist as List = [cannon, minigun, rail, gauss, rockets5, rockets13, missile, torp]
#public gunlist as (Transform) = array(cannon, minigun, rail, gauss, rockets5, rockets13, missile, torp)
#public gunlist as ArrayList = (cannon, minigun, rail, gauss, rockets5, rockets13, missile, torp)
more ▼

asked Feb 28 '11 at 04:20 AM

Sam 5 gravatar image

Sam 5
12 6 6 9

ok, I got it to work with List by just declaring "Private gunlist as List" and then under update starting with "gunlist as List = [cannon, minigun...]" I'm still curious how to do this with arrays or built in arrays, however. Just for future reference.

Feb 28 '11 at 04:29 AM Sam 5
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

Just do

public gunlist as (Transform)

Then assign the prefabs to the array. Having them separately and as an array kind of defeats the purpose of using an array in the first place.

more ▼

answered Feb 28 '11 at 04:32 AM

Eric5h5 gravatar image

Eric5h5
103k 50 166 622

(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:

x1888
x1887
x723
x95

asked: Feb 28 '11 at 04:20 AM

Seen: 1565 times

Last Updated: Feb 28 '11 at 04:20 AM