Here is a few common, but also easy to use several methods of platform judgment.
1. First of all, it is also a handy one for me. Using Runtimeplatform to judge, the explanation on the API is that [the platform application is running. Returned by Application.platform.]
For a chestnut: if (application.platform = = Runtimeplatform.windowseditor) {}
Generally used is three platforms, Android [Android], Apple [iphoneplayer],unity Editor [Windowseditor].
2. The platform-dependent compilation in the editor [Platform Dependent compilation], you can use the if...else ... Differentiate the code on different platforms.
Chestnut Code:
void Awake () { #if unity_android Debug.Log ("Here Android Device"); #endif #if unity_iphone Debug.Log ("Here Apple Device"); #endif #if unity_standalone_win Debug.Log ("Run O on Computer"); #endif }
3. See the code that someone posted, I glued it in case of use.
Switch (application.platform) {case runtimeplatform.windowseditor: print ("Windows"); break; Case runtimeplatform.android: print ("Android"); break; Case Runtimeplatform.iphoneplayer: print ("Iphone"); break; }
Finally, posted on the official website of the API, the specific platform on the official website has introduced, official website address: https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
The judgment of several unity running platforms