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:
3 Answers
3Change 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.
– hexagoniusI 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
What platform do you have selected on your build settings,
– Adamcbrzthey 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).
– hexagoniusCool! Post back to let us know ;)
– Glurth