Hi, I am making a game and in this game I want to remove from inventory an item which has a durability null (is broken). What I have in mind is when the OnDurabilityNull Action of the item is call, unequip it (if it is an equipement) and remove it from the inventory.
I have some items (Item, shield, usables, spells, armors and weapons) which are scriptableObjects. They all inherit from Item class but some items have the IDurability interface like armors or weapons.
As we can’t GetComponent of a scriptableObjects, I try to cast the item into an interface like that:
IDurability interfaceDurability = (IDurability) item;
if the item is an armor or an weapon, no error but if it is not, an error appears to say “cast is not possible”.
There is a way to do that ?
I thought to a generic method in item class to return :
public T Get<T>() where T : interface
{
try
{
return (T)this;
}
catch (Exception)
{
return null;
}
}
But It doesn’t work since we can not use this syntaxe where T : interface.