So a couple of weeks ago, my wife and I went on our honeymoon to St. John in the Virgin Islands. The trip was AWESOME. St. John is absolutely gorgeous (like a screensaver), and we relaxed big time with a lot of snorkeling, hiking, reading, etc. On the plane ride home I spent some time working on something called Armory – a simple framework to add stats to a character in Unity and modify them through things like equipment and buffs/debuffs. I didn’t get very far on the plane, since I started reading the new Bobby Fischer biography and couldn’t put it down.
My plan was to finish this project up in my spare time, but unfortunately my laptop completely died right after I got home. I ordered a new one, but this whole thing kind of put a damper on Armory, at least for now. I managed to grab the project off of my comatose laptop, and thought that the unfinished project might help someone out – so I decided to throw it up online.
Here’s a webplayer example if you want to check it out (click the image below). You can see a simple set of defined stats (Strength, Intelligence, and Agility), with some different ways to modify them: equipping weapons and casting buffs/debuffs. This isn’t anything super sophisticated, and the UI is obviously primitive, but if you are interested in this type of functionality in your game, it might help you get started.
I didn’t finish the project, as mentioned above, but here’s what you can do.
Check out StatController.cs, or the StatController component on the Hero game object included in the demo scene. In here you’re able to create a bunch of stats, along with some different options to control their behavior:
- Minimum and Maximum values for the stat.
- Starting value. Right now this is just a single simple value, but I was planning on adding some sort of mechanism to allow each stat to grow as the character ‘levels up’ – a concept that never made it in here.
- Clamp type for the value. All stats are floats deep down. Do you want the stat to use the raw float value, the floor, or round to the nearest int.
If you check out the example, you’ll see Strength, Intelligence, and Agility stats defined to range from 0 -> 100.
Equip Weapons and See Stats Change
Check out Inventory.cs or the Inventory component on the Hero game object in the included demo scene. This is just a basic inventory system that allows you to define a list of weapons and switch between different equipped weapons.
Each weapon has a list of StatModifers that control how the weapon affects the Hero’s stats when equipped. StatModifers allow you to control the following:
- Which stat to modify. Right now this is just a string, but if I kept working on this it might be nice to get an enum or something that reads from the values you setup in the StatController.
- How much to modify the stat by. Currently Armory only support additive modifications, but if I kept working on this I would probably add more functionality here. It might be useful to have a sword that increases you strength by 5% instead of an absolute quantity.
- How long to modify the stat for, < 0 = permanent. As you equip and unequip weapons it adds/removes permanent StatModifiers.
This code should be pretty straightforward.
Buff and Debuff Your Character
Spellbook.cs defines some simple spells that can be used to buff and debuff your character. Click around in the demo and you will see them working. These buffs use the same StatModifiers that the Inventory uses, but they are timed and not permanent – they wear off over time.
I think that pretty much sums it up. An unfinished project that just happened to be in the wrong place at the wrong time when my laptop decided to check out. Hopefully it is useful to someone anyway! Feel free to use this code for whatever you want, please just drop me a line and let me know what you are using it for.