It would be nice to alphabetically sort the words in the inventory list, both for neatness and consistency (so that, in a game, if we pick up a key and a heart, it will look the same, regardless of the order they are picked up in), but also so that items of the same type will be listed together so that we can easily see how many of each item we are carrying.
To implement alphabetical sorting for the items in the inventory list, we need to do the following:
- Add the following C# code to the beginning of the OnChangeInventory(...) method in the PlayerInventoryDisplay script class:
public void OnChangeInventory(List<PickUp> inventory){ inventory.Sort( delegate(PickUp p1, PickUp p2){ return p1.description.CompareTo(p2.description); } ); // rest of the method as before ... }
- You should now see all the items listed in alphabetical order.
This C# code takes advantage...