#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?

You want to use

#if UNITY_IPHONE && !UNITY_EDITOR

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)