Omg whar am i??

How can I tell in my code whether or not I’m in the Unity editor or on an actual iPhone?

I need some things (like store kit purchases) to ‘fake it’ when they’re in Unity itself, and to work properly when they’re on the device.

#if UNITY_IPHONE reports back true, since I’m building an iPhone app. So that won’t do.

Thanks!
-Chilton

#if UNITY_EDITOR

#endif

Unity Manual: Platform Dependent Compilation

Awesome :slight_smile:

I tried that and it wasn’t returning the right answer all the time, which is why I came here.

But I tried it again just now, it seems to be working. Pretty sure it was just a typo on my part.

Thanks!
-Chilton

The #if flags will tell you if you’re compiling for the phone or the editor. However, when you switch platform to iOS in build settings (as you might do when preparing to make an iOS build), then the code will be compiled with #if UNITY_IPHONE being true. This is useful for making sure your iOS code doesn’t have bugs.

However, if you need to know what device you’re actually running on, then you can check the Application.platform variable (RuntimePlatform.IPhonePlayer would be the one for iOS). If you need to know more specifically whether it’s an iPhone or iPad, you can check the iPhone.generation variable.