#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:
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 $$anonymous$$onoDevelop Project).
Answer by Positive7 · Sep 06, 2015 at 07:14 PM
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 $$anonymous$$onoDevelop as:
it does not offer autocompletion for
UNITY_ANDROID
if build settings are set to something else than Androidit does not offer autocompletion inside
#if UNITY_ANDROID
#endif
Answer by Bloke28 · Apr 02, 2019 at 11:47 PM
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
Answer by Don-Tako · Nov 14, 2018 at 01:16 PM
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.