- Home /
Learning inheritance, need clarification
I'm making a medieval RTS to help further my understanding of object oriented programming as the two things seem to go hand in hand. I understand how inheritance allows one class to be granted all the features of another class, and I'd like to use that to make my units unique and easy to instantiate.
For instance, all my units have to have some health, but only the king gets armor (maybe unrealistic but I'm just getting my point across). So I have a Person.js script that defines health as a variable, and then a King.js script that extends Person and also defines armor as a variable. All this is gravy, but I'm still trying to figure out how to do one thing:
Is there a way to show the appropriate variables in the Inspector window the way you'd see them if they were just defined in a regular script? I.e., if I click the king, I'm able to see Health and Armor, and if I click another unit, I just see Health? Right now all I see is the script in which I define a new King object, but I don't get to see any of the variables without printing them to the console to verify that they work.
Answer by MakeCodeNow · May 07, 2014 at 05:09 AM
The inspector should automatically show all public (i.e. non private) vars in your component when you select the object. I bet that your variables are all private, hence the problem.
I was an idiot and declared my variables in the Start method, but you're quite right. Thanks man.