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
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, minigun...]" 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
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.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
Keep adding targets to a list
Dynamic Enemy Transform List
Disable All Transform In List
A node in a childnode?
How To Get A Reference To All Nearby GameObjects?