0

What would be the easiest way to take 2 items from a list and switch their places. So if i had a list like that

public List<GameObject> itemsInInv = new List<GameObject>();

and i wanted display the list graphically. using something like

    var len = currentPosition;
    items.transform.localPosition = new Vector3(44 * (len % 4), -36 * (len / 4), 0f);

you could easily remove an item from the list with seomthign like

    itemsInInv.Remove(obj.gameObject);
    Destroy(obj);

then call something to re-sort the list kinda like

    for(var i =0; i < itemsInInv.Count; i++)
    {
        itemsInInv[i].transform.localPosition = new Vector3(44 * (i % 4), -36 * (i / 4), 0f);
    }

But say i wanted to switch 2 of the items in the list, how would i do this? My guess is id have to cut the list into 2 list and replace them together, not really sure :)

Sniffle6
  • 149
  • 1
  • 14

0 Answers0