Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Doing equipment. I wrote some scripts

Discussion in '2D' started by lordpfeif_unity, Oct 14, 2019.

  1. lordpfeif_unity

    lordpfeif_unity

    Joined:
    Aug 20, 2019
    Posts:
    5
    public bool AddItem(EquippableItem item, out EquippableItem previousItem)
    {
    for (int i = 0; i < equipmentSlots.Length; i++)
    {
    if (equipmentSlots.EquipmentType == item.EquipmentType)
    {
    previousItem = (EquippableItem)equipmentSlots.Item;
    equipmentSlots.Item = item;
    return true;
    }
    }
    previousItem = null;
    return false;
    }

    public bool RemoveItem(EquippableItem item)
    {
    for (int i = 0; i < equipmentSlots.Length; i++)
    {
    if (equipmentSlots.Item == item)
    {
    equipmentSlots.Item = null;
    return true;
    }
    }
    return false;
    }
    }
    With the code for our EquippableItems but we want to further divide it into two classes EquippableItem and EquippableWeapons but this is the part of the code that controls adding is their a way i can just add EquippableItem and weapons at the same time or do i have to write from the ground up?
     
  2. lordpfeif_unity

    lordpfeif_unity

    Joined:
    Aug 20, 2019
    Posts:
    5
    Fun fact i have tried the inhertaince of stating EquippableWeapons : EquippableItems this works till we hit the actually equip button.