Hello, first of all, sorry for not enough specific title.
So, I have:
public Item[,] inventory;
where are stored items that player has. Item is a base class with some variables like Name. For simplicity lets say that I have only 2 child classes - “Armor” and “Weapon”. Class Armor has Getter/Setter int “ArmorValue” and Weapon has Getter/Setter int DamageValue. Now I am working on a GUI.Box that will show you some information about item when you enter your mouse on its icon in your inventory.
And I want it to display proper variables. If it is Weapon, then display Name and DamageValue. If it is Armor, display Name and ArmorValue.
I made this, but I can’t access these variables.
// pointedSlot is just an array with 2 values. Simply, it tells on what item is your mouse pointing.
string textToDisplay = "";
// if you're pointing on an Item that is Armor, then do this code. If statement works just fine.
if(inventory[pointedSlot[0], pointedSlot[1]].GetType() == typeof(Armor)) {
// and now... Even though it is clear that we are pointing on an Armor, we can not access ArmorValue, because Item does not contain this variable.
textToDisplay = inventory[pointedSlot[0], pointedSlot[1]].Name + "
Armor: " + inventory[pointedSlot[0], pointedSlot[1]].ArmorValue;
}
if(inventory[pointedSlot[0], pointedSlot[1]].GetType() == typeof(Weapon)) {
textToDisplay = inventory[pointedSlot[0], pointedSlot[1]].Name + "
Armor: " + inventory[pointedSlot[0], pointedSlot[1]].DamageValue;
}
GUI.Box(new Rect(Event.current.mousePosition.x - _tooltipWidth, Event.current.mousePosition.y - _tooltipHeight, _tooltipWidth, _tooltipHeight), textToDisplay);
So, guys, is there some way to fix this? I am grateful for any help.