- Home /
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)
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, $$anonymous$$igun...]" I'm still curious how to do this with arrays or built in arrays, however. Just for future reference.
Answer by Eric5h5 · Feb 28, 2011 at 04:32 AM
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.
Your answer
Follow this Question
Related Questions
Keep adding targets to a list 2 Answers
Disable All Transform In List 1 Answer
A node in a childnode? 1 Answer
Dynamic Enemy Transform List 1 Answer
Converting Builtin Array to Generic List 2 Answers