Sl0thzy Sl0thzy - 1 year ago 158
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 Source

You can't do this.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download