Designing the hierarchy of the game

Coming from heavy OOP background, it’s usual for me to do Object-Oriented Design when it comes to designing data structure/classes. But somehow it’s hard to get the idea around when scripting in Unity.

So here’s the idea:

  • I have a character that can be attached to a troop which the character will lead
  • The character has 3 item slots he can equip
  • The item have attributes that can enhance the character’s attribute
  • Finally, once the character attached to a certain troop, character’s attribute (including the 3 items it equipped) and troop’s attribute will be added together in the gameplay
  • Additionally, the character can have certain skills/abilities of which can be enhanced from certain unique item (i.e. : Drain staff which has “Blood Drain” level+5 can enhance the skill of a character that has Blood Drain leveled to at least level 1)

So it’s natural to create a class (script) called attribute, which contains integers HP, attack, defense, etc.
So far so good until that point; Until I realized that you need to create a GameObject for every script you want to run. Now that what stops me from advancing further because there is this whole scalability issues.

The current design of my classes is as such

Attribute.js

var attrTyp         : int; // 0=item attribute, 1=character attribute 2=troop attribute

var hp              : int;
var atk             : int;
var def             : int;
...
Item.js

var itemSlot        : int      ; //0=head, 1=armor, 2=feet, etc
var availableForJob : boolean[]; //which type of job can wear this item.
var attrGiven       : Attribute; 
var itemID          : int      ;
...
Skill.js

var sklID : int;
var level : int;
Character.js

var skillLevel      : int[] // array of skills, containing the level of skills
var skillLevelReq   : int[] // if character level is less than skill level req, modifying skill level is impossible
var itemEquipped    : Item[];
var baseAttr        : baseAttr;
...

When I want to assign an item to a character at Start(), I need to create GameObject. What if the number of equip slot increases to 16? I need to create 16 Item GameObjects on the scene and there will be 16 Attributes need to be generated. And if I need to display 8 characters at once in a scene, there will be a huge amount of “junk” GameObject attached with a single script. Is there a work around to this problem?

I appreciate any input you can give, especially from veterans.

Thank you In Advance,

Considering that pasting code here never works for me, here is a Pastebin link to a system that I use for creating an inventory of items. It’s in C# but it shouldn’t be too difficult to translate to JS.