Operator '==' cannot be used with a left hand side of type 'InventoryItem' and a right hand side of type 'System.Object'.

I keep getting this error when trying to run this code could anyone help me I have provided the code to see exactly where the problem is coming up.

function UseItem(item: InventoryItem, amount: int){

if(playerInventory[item] <= 0) return;

playerInventory[item] -= amount;

switch(item){
	case InventoryItem.FACTS:
		playerStatus.AddFact(factsAmt);
		break;
	case InventoryItem.PILLS:
		playerStatus.AddPills(pillsAmt);
		break;
}

}

I have the same problem.

I have the same problem.

You can’t switch on a user-defined type. It looks like you’re trying to use InventoryItem as an enum. If that’s the case, you should accept an int instead of an InventoryItem, and you’ll be able to switch on that.

I.e.:

enum blah { one = 1, two=2 }

function DoStuff( x : int ) {
 switch ( x ) {
  case blah.one: break;
  case blah.two: break;
 }
}

function Update() {
  DoStuff( blah.one );
}