The judgment of several unity running platforms

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.