00yoshi
1
I want to make a platform dependent compilation in a class, but UNITY_ANDROID doesn’t exist in MonoDelevop, the only things which exist beginning with UNITY_ are: UNITY_5, UNITY_5_1, UNITY_5_1_1, UNITY_ASSERTIONS, UNITY_EDITOR, UNITY_EDITOR_64, UNITY_EDITOR_WIN, UNITY_STANDALONE, UNITY_STANDALONE_WIN.
I didnt find a solution on google and the help page in the docs says that things like UNITY_ANDROID exist. It looks like this:
Change your build settings to Android and it will Popup in MonoDevelop. You can keep continue using #if UNITY_ANDROID while build settings is set windows or whatever. Once you change to Android it will get compiled.
You can also check it if you click Build Settings → Android → Switch Platform
then switch to mono and check your code highlight as normal inside Android endif and any other platform become gray highlight (skin dependent color).
You also can do:
if(Application.platform == RuntimePlatform.Android)
{
//... do stuff
}
I like to use both, what it does is says if build settings are android, then add this code,
and then if your current system device is android then run this code.
So when in editor testing it won’t run the code but it remains there if your build settings are set to android.
The Same can be done for the editor.
#if UNITY_ANDROID
if(Application.platform == RuntimePlatform.Android)
{
/* Do Stuff */
}
#endif
#if UNITY_EDITOR
if (Application.platform == RuntimePlatform.WindowsEditor)
{
Debug.Log("Button Pressed in Editor");
}
#endif