Hello i have this methods in my script
This method adds item to list:
public void Equip(Equipment newItem, ItemType2 itemType)
{
Equipment oldItem = null;
if (itemType == ItemType2.laser)
{
//addToArray(newItem);
lasers.Add(newItem);
//Debug.Log("Laser added");
}
if (itemType == ItemType2.engine)
{
engines.Add(newItem);
//Debug.Log("Engine added");
}
if (onEquipmentChanged != null)
{
onEquipmentChanged.Invoke(newItem, oldItem);
}
}
This method removes item from list:
public void UnequipLasers(int slotIndex)
{
if (lasers[slotIndex] != null)
{
Equipment oldItem = lasers[slotIndex];
inventory.Add(oldItem);
lasers[slotIndex] = null;
//lasers.RemoveAll(x => !x);
lasers.Remove(null);
if (onEquipmentChanged != null)
{
onEquipmentChanged.Invoke(null, oldItem);
}
}
}
This method removes all items from lists:
public void UnequipAll()
{
for (int i = 0; i < lasers.Count; i++)
{
UnequipLasers(i);
//lasers.RemoveAll(x => !x);
}
for (int i = 0; i < engines.Count; i++)
{
UnequipEngines(i);
}
}
But i want to delete empty item from list, after i removed item
If i use
lasers.Remove(null);
in 2nd method then my 3rd method doesn’t remove all items, it removes only 1 item at time
How do i fix this ?