#if UNITY_IPHONE code runs when played in Editor

for (int i = 0; i < 6; i++) {
#if UNITY_IPHONE
Debug.Log(“iPhone Only”);
#endif
Debug.Log(i);
}

I would have expected the iPhone Only not to print in the editor, but it does, which is extremely annoying, but more troubling is that it only prints 1 out of the 6 times in this IF statement. Why?

3 Answers

3

You want to use

#if UNITY_IPHONE && !UNITY_EDITOR

arrgh... too late x)

–

It should also be possible to use logic operators in preprocessor directives like this:

#if UNITY_IPHONE && !UNITY_EDITOR
...

The editor will define UNITY_IPHONE when the build platform is set to iOS.

If you don’t want this to happen you should just add this line:

if(!Application.isEditor),The Editor will run code with UNITY_IPHONE defined when you’re build platform is set to iOS. If you don’t want this to happen you can simply add a non-preprocessor statement like this:

if(!Application.isEditor)

That's good to know, but still doesn't answer the question: Why does the code above result in the following Debug Log output: iPhone Only 0 1 2 3 4 5 I expect it to produce something more like: iPhone Only 0 iPhone Only 1 iPhone Only 2 iPhone Only 3 iPhone Only 4 iPhone Only 5

–

from the code you included I would expect the latter to be the output. So I'm not sure what's happening there. Is that the exact code you're using? if not please include the actual code.

–

It's because you have "collapse" turned on in the console.

–