Hi guys, I want to implement the Sorting System like found in the many games on their Inventory or that requires a Sorting System. So, I have found a way to implement the Sorting System in my game and I compare it with the Item Name that stored in the Item Manager class. However I got these following errors, both in the Unity itself and from the code.
Inside Unity:
Assets/Scripts/SortingList.cs(6,19):
error CS0539:
`System.Collections.IComparer.Compare’
in explicit interface declaration is
not a member of interface
Code:
I have these items in the Inventory:

and I want those items will be sorted automatically by their given name.
Here is the code that I am using:
Sorting List Class:
using UnityEngine;
using System.Collections;
public class SortingList : IComparer
{
int IComparer.Compare(ItemManager x, ItemManager y)
{
return ((new CaseInsensitiveComparer()).Compare(((ItemManager)x).itemName, ((ItemManager)y).itemName));
}
}
Inventory Class:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class Inventory: MonoBehaviour
{
SortingList comparerMethod;
List<ItemManager> slots; // Hold all of the items in the inventory
void Start()
{
comparerMethod = new SortingList();
}
void Update()
{
slots.Sort(comparerMethod); // This is where the error in the code shows.
}
}
Item Manager Class:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class ItemManager
{
public string itemName;
}
Any help would be appreciated
Thanks
