#if UNITY_ANDROID doesn't exists in unity 5

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:http://puu.sh/k1Ty4/1da995c04f.png

What platform do you have selected on your build settings,

they should exist, I use them with Unity 5.1.2f4 maybe making the endif followed by if an elif (for elseif). Also try resyncing mono from Unity via Assets > Sync MonoDevelop Project).

Cool! Post back to let us know ;)

3 Answers

3

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).

I have the feeling the "problem" comes from MonoDevelop as: 1. it does not offer autocompletion for UNITY_ANDROID if build settings are set to something else than Android 2. it does not offer autocompletion inside #if UNITY_ANDROID #endif

You also can do:

if(Application.platform == RuntimePlatform.Android)
{
 //... do stuff
}

This is not the same thing as this code stays while the other gets completely stripped.

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

because Time.deltatime is a float and if i use them as a int I will get an error.