Sl0thzy Sl0thzy - 16 days ago 5
C# Question

Comparing enum values in C#/Unity?

I was wondering if it is possible to compare the (int) of two seperate Enums (from different scripts)?

I am currently trying:

if((int)newMiner.minerType == (int)resourceType)
{
Debug.Log("Resource Holder Accepts Miner");
}


newMiner is the other script that has the enum I'm trying to compare and minerType is one Enum while resourceType is the local Enum I am trying to compare it with.

What I have now does not return an error, however, it always returns true. Any information on how this does/doesn't work would be very much appreciated :)

Answer

You can't do this.

Just have one publicly-available enum! Use the same in both places.