So I’m pretty new to coding but I’ve been working on a simple inventory and I decided to redo my item classes after some thinking.
One of the classes (which inherits from the item class) is called StatItem. Which is just an item class for items which modify stats on a character.
It only has 2 additional variables, the int BuffAmount and the Attribute TargetAttribute (the attribute class has 3 values: name, basevalue and buffvalue)
public class StatItem : Item {
public int buffAmount;
public Attribute targetAttribute;
public StatItem (...(the item class constructors)..., int amountToBuff, Attribute attributeBuffed)
{
buffAmount = amountToBuff;
targetAttribute = attributeBuffed;
}
public static void UseStatItem (StatItem itemUsed){
itemUsed.targetAttribute._buffValue += itemUsed.buffAmount;
Debug.Log ("function " + itemUsed.targetAttribute._name + itemUsed.targetAttribute._buffValue);
}
So with my current method I can define in the ItemDatabase which Attribute is targeted, which for the moment is:
GameObject.FindGameObjectWithTag("Player").GetComponent().playerStats.strength;
.
However!! I’d like to be able to define the target character in the UseStatItem method but still have which attribute on that character (ie strength, agility…) defined on the database.
So my initial plan was on the database to have target.strength as the Attribute (target being a CharacterAttributes variable that I made a class of) and then define the target in the method. However for some reason (and my theory is, is that it’s because the database is created OnStart and then not updated) the target CharacterAttributes is updated but the targetAttribute is not.
I hope I’ve explained okay :s
So basically what catastrophically dumb thing am I doing, is there a way of doing what I want? Am I making it all too complicated?