- Home /
Items with Statistics(such as attack damage) that actually effect the character?
I have a list of all of my items, now I just need to provide functionality to those items when they are equipped. Is there a simple way of giving those items functionality, such as a Short Sword that has 1 Pound of Weight, +5 to attack damage and actually having that attack damage be added to my character's damage when he has that weapon equipped?
(The only way I can fathom is creating a function for EACH item, and being that there are about 300 items, that sounds like not such a simple way, so before I jump into that I would like to know if there's a simple method I'm overlooking)
Are you familiar with the idea of class inheritance?
Well, I may have be misunderstanding your question, but it seems that this can be solved with class inheritance.
Unityscript supports class inheritance, like this explains. I mainly code in C#, so perhaps somone else can fill you in on any gotchas
Answer by Kiloblargh · Mar 08, 2013 at 07:35 AM
You don't need a function for every item. It would be simple enough to have a script on every item, and make it be the same one script, (attached to the prefab) with inspector-settable fields for every possible effect an equipped item can have, and if the item does not affect that attribute, you just leave it set to zero. Then the various action functions in your player's script add up the relevant variables to that action from all the players' equipped items.
Brilliant. Thank you. This was pretty much exactly what I was looking for, and normally the kind of simple solution I overlook.
Not sure if you'll even check to get back to me on this, but using this method, how do I go about adding these prefabs into my active inventory list?
Answer by Ryzokuken · Mar 08, 2013 at 07:01 AM
An easy way of providing them with different specific damages is to use a health bar just like hack and slash rpg
and attaching a script named something like damage to each weapon where you import the adjustCurrentHealth or any similar variable and make it public so you can adjust it different for each weapon...
What it does is adjust the adjustment or damage it does to the enemy health, so each weapon can have a different attack damage
HOPING IT SOLVES YOUR PROBLEM,
~FORSAKEN
While this does seem like a viable option, I'm looking for some kind of simple method I've just not thought of, or have overlooked. This sounds like a working method, but I have items such as chestpieces that add weight, armor, magic resistance, health, etc, etc. and it seems like an overly-complex way of going about it. Again, maybe that's just how it's done but with most things I've learned with Unity, and scripting, is there's always a method I've overlooked that simplifies things. Like when I learned how to use interfaces. What a saver that is.
For making that, you need a more complex player affecting system where many more things matter than just sheer health...
As to having magic, I think that a mana or spirit bar just like health bar can be easily created and different scripts attached to your player where pressing a button would create a spell which decreases your mana and target's health by a constant value.
Or you can make the values public and attach the same script for each magic but the value of mana cost and damage can be adjusted in the GUI.
Good ideas, again, but another person ($$anonymous$$iloblargh) gave me a very simple and effective solution above. Thank you for your help, though.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
[SOLVED]Possible Alternation of Transform.Rotate 1 Answer
editor script makes editor crash 1 Answer