- Home /
The question is answered, right answer was accepted
Vehicle Upgrade System
Hi all,
Imagine you are playing a game. You buy a fighter and get enough experience to upgrade it. You talk to a "mechanic" and a window comes up with buttons displaying the pictures of the components to be upgraded.
And this is where I got stuck.
How would I go about creating a script that will be attached to the "mechanic" that will allow many vehicles to be upgraded with many upgrades. (the upgrades are physical components like new engines, turrets etc requiring the instantiation and parenting of prefabs).
I can create menus and instantiate things but have no Idea how I should do the rest. Arrays have been suggested to me but are handled differently in unity to what I am used to.
Any and all help is appreciated.
Thanks.
Answer by celadon · Feb 14, 2011 at 07:20 AM
If you are able to program in C#, you can go beyond arrays and use some of the generic collections to simplify things for yourself. I would think you'd probably want to create some kind of hierarchy of classes to store your upgrade data - e.g. you could start with a class like VehicleUpgrade that stores data like upgrade name, the type of vehicles it applies to, the upgrade category, etc. - but I am sure it will get more complicated quickly. For example, you may have different classes you can add into this one that represent different upgrade components and store their data.
If you are using C#, then you can use collections like strongly-typed lists or dictionaries (e.g. List or Dictionary which is much easier to use and more type-safe than just a plain old array.
But really, for a system like this, it seems like how you structure all of the data about a given upgrade is a lot more complicated than how you store the different upgrades themselves...
@$$anonymous$$yth: UnityScript has support for at least some of the generic .NET containers, such as List, as well. (I can't tell you off the top of my head what other containers are or are not supported.) In any case, you should definitely be abe to implement what you describe using UnityScript.
I agree, you can certainly do something like this in either JS or C#. I$$anonymous$$O, the issue of what kind of collection to use is a distraction. You have a lot of info to keep track of - e.g. the name of the prefab, the texture to use in the GUI interface, cost, whatever. You need to figure out how to structure it all logically before getting worried about how to store it in the code. The logical structure will deter$$anonymous$$e the specific implementation you need.
Answer by Jesse Anders · Feb 14, 2011 at 03:54 AM
Arrays have been suggested to me but are handled differently in unity to what I am used to.
This is probably where I'd start. In C# at least, arrays are handled no differently in Unity than anywhere else. I'm not that familiar with array use in UnityScript, but I do know that the idiosyncratic way in which multi-dimensional arrays were handled has been addressed in the latest version of Unity. Aside from that, I'm willing to bet array use in UnityScript is pretty conventional as well.
So, perhaps you could edit your post (or post a comment) and describe in what way array use seems to differ from what you're used to. Arrays (and containers in general) are invaluable tools, so if there's something keeping you from using them, that's the problem you'll want to address first (IMO).
The arrays I have used in the past used a co-ordinate system to access and were like a filing system that up to 255 boxes and within each of those, up to 255 more and so on up to 255 times.
If you mean a multi-dimensional array, then those are supported and shouldn't be any different from what you've encountered in the past. In any case, there's nothing unusual about how arrays and other containers are handled in Unity, so don't hesitate to make use of them.
Follow this Question
Related Questions
2D Animation does not start 1 Answer
unity 5 upgrading errors 1 Answer
car slides to the right or left when i accelerate... why? 2 Answers
Vehicle sound help? 1 Answer
Raycast Car-Vehicle Physics 1 Answer