#if UNITY_IPHONE in javascript

Hi all!

Is there a way to get following code running in javascript?

#if UNITY_IPHONE
// iphone code
#else
// not iphone code
#endif

Thx for any help!

you could use if(Application.isEditor())

That’s not the same… The former will execute both on the device and in the editor, because they’re both “Unity iPhone”, while the latter will return false on the device and true in the editor.

there are no defines etc in JS
this capability is strictly C# only

ok thx… bad news!

Well, you could create a C# script with compiler directives that sets a boolean somewhere, and then you can access that from js (never tried both js and c# in one project so it probably won’t be that simple, but it should be doable).

Would

if (Application.platform == RuntimePlatform.IPhonePlayer) {
// iPhone code
} else {
// Non iPhone code
}

work?

partially. the iphone define works on the player and the editor, while this check would only work on the iphone itself. yet its naturally much better than no check :slight_smile:

Would like to see the OP’s issue included in .JS too.

my 0.02 :wink:

I came across this thread after finding this. It looks like it will work in JavaScript/UnityScript as well. I use it in a couple of places for mobile-specific things and it works great.