Why is Unity identifying my computer as both a Windows and a Mac?

I’m writing code on Windows that needs to be compatible with both Windows and OSX computers. I know that to write platform-dependent code you have to use #if statements, but I’m having trouble with it.

Here’s an example of the kind of code I’ve been writing:

    public bool isWindows = true;
    public bool isWindows = false;

    public bool isOSX = true;
    public bool isOSX = false;

I know this looks redundant, but I need it to prove a point. If I use Debug.Log to print out the value of these booleans, I get this:

isWindows: TRUE

I don’t understand why, but Unity seems to think my computer is both a Windows and a Mac. I’m testing this in the Windows editor, but it isn’t exclusive to that. When I was testing it on the Mac standalone version, it was recognising the computer as a Windows there too.

Can anyone explain why this might be happening?

Are those public fields in a serialized class? That means once the value has been set it doesn’t matter what you set in the field initializer since the value is deserialized before Awake. Make sure you don’t serialize the values. Either by using the [NonSerialized] attribute or simply by making it static. “Static” or “const” would make the most sense here since those are in fact constants.

Unity doesn’t “think” ^^. The preprocessor tags are simply set automatically depending on the platform. And no, it will never set windows and mac tags at the same time.