- Published on
Summary of how to identify platforms in Unity
- Authors
- EvelynFull-time IndieDev.I'm Japanese, so please forgive me if my English is strange.
Hi! How are you doing?
To help you out, I have put together a method to determine the platform on which the game is running.
In this article, we will cover the following three methods:
- Using Platform Dependent Compilation
- Using Application.platform
- Using Debug.isDebugBuild
Using Platform Dependent Compilation
By using Platform Dependent Compilation, you can separate the code according to the platform at compile time. By using Platform Dependent Compilation, we can separate the code according to the platform.
The actual code is written as follows. you can use if, else if, else
#if UNITY_EDITOR
Debug.Log("Unity Editor");
#elif UNITY_IPHONE
Debug.Log("iOS");
#elif UNITY_ANDROID
Debug.Log("ANDROID");
#else
Debug.Log("Any other platform");
#endif
Pleaes read the official documentation for details.
#define directivesUsing Application.platform
Also, by using Application.platform, you can determine the platform at runtime.
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
Debug.Log("iOS");
}
else if (Application.platform == RuntimePlatform.Android)
{
Debug.Log("ANDROID");
}
else if (Application.platform == RuntimePlatform.WindowsPlayer)
{
Debug.Log("Windows");
}
else {
Debug.Log("Any other player");
}
Pleaes read the official documentation for details.
RuntimePlatformUsing Debug.isDebugBuild
Debug.isDebugBuild can be used to determine if the program was built in debug state.
if (Debug.isDebugBuild)
Debug.Log("Now debug build");
Summary of this article
This is how to judge each platform.
Please try to use the contents of this article to define the behavior for each platform.
I hope this article will be useful to you in your game development.