First of all I would like to say I am still very confused trying to understand how many concepts of the UIS work so the more detailed you are the better. I managed to set up equipping/unequipping weapons from the inventory(drag and drop to equip slots) through the Equipper.cs. My weapons logic is a monobehaviour on the weapon prefab and its unrelated with UIS (also i would like to add that I am not using any opsive controller but a custom one i made). The thing is, that weapons have durability that goes down with each shot, and when durability gets depleted(<1) the weapon gets destroyed so does its gameobject.
My issue now is when the weapon gets destroyed, It is still equipped as an item on the equipment slot and therefore also still exists inside the main inventory, which means that if i unequip the weapon and then equip it again there it is again a new instance of that weapon as a gameobject with full durability.
I want to be able to unequip the weapon item but also completely remove it from the main inventory.
What i attempted with failed results is adding an ItemObject MonoBehaviour on the weapon game object, setting the weapon item definition as its item, and then through code accessing the ItemInfo and trying to remove it from the main inventory. (See code below for a more clear view of what i am saying here).
P.S. In general I would like to handle something like an OnWeaponEquip and OnWeaponUnequip event that i can subscribe to because Armor and Weapon will also have stats that i want to manipulate. I think this goes hand in hand with the above, so if the solution for the main issue can cover this also all the better. I tried looking at the demo but I am lost i could not understand what happens where I prefer to simplify the logic to my understanding
My issue now is when the weapon gets destroyed, It is still equipped as an item on the equipment slot and therefore also still exists inside the main inventory, which means that if i unequip the weapon and then equip it again there it is again a new instance of that weapon as a gameobject with full durability.
I want to be able to unequip the weapon item but also completely remove it from the main inventory.
What i attempted with failed results is adding an ItemObject MonoBehaviour on the weapon game object, setting the weapon item definition as its item, and then through code accessing the ItemInfo and trying to remove it from the main inventory. (See code below for a more clear view of what i am saying here).
C#:
public virtual void HandleWeaponDurability()
{
if ((durability -= durabilityLossPerShot) <= 0)
{
Debug.Log("Durability Depleted");
DestroyWeapon();
}
}
private void DestroyWeapon()
{
ItemInfo equippedItemInfo = GetComponent<ItemObject>().ItemInfo;
playerCharacter.Inventory.RemoveItem(equippedItemInfo);
Destroy(this.gameObject, 0.3f);
}
P.S. In general I would like to handle something like an OnWeaponEquip and OnWeaponUnequip event that i can subscribe to because Armor and Weapon will also have stats that i want to manipulate. I think this goes hand in hand with the above, so if the solution for the main issue can cover this also all the better. I tried looking at the demo but I am lost i could not understand what happens where I prefer to simplify the logic to my understanding