Problem: The game developed by the company is actually running on the Android platform, but we are developing on the Windows platform. OK. It is often necessary to switch to Android after development in some places, code can be differentiated based on different platforms
A: unity can be determined by the provided variables during compilation. The following is the reprinted content. Address:
While unity is already quite convenient when making cross-platform games, we often need to append dedicated code to handle performance and functional differences between platforms, although the unity API already has application. platform allows us to make judgments, but some runtimeclasses may return errors when bulid is not applicable to platforms, such as iPhone esettings or iPhone keyboard. When bulid is a PC platform game, an error is reported directly, but not bulid.
In addition, when a new version of unity is released, some changes may also be made to the script syntax, such as the latest version 3.4. The official update details page mentions changes to JavaScript, it is also suggested that an error may be reported after the old program is updated to the new version of unity. At this time, we must adjust the program content to make the game work properly.
Based on the errors that will occur during compilation, even if we add application to the program. platform or application. unityversion does not help much to determine whether the execution platform or unity version is used. Therefore, you have to annotate the currently unavailable program segments during compilation on different platforms to avoid errors, however, this approach is inconvenient, especially when the program is written more frequently, the chance of a problem is even greater. Fortunately, Unity provides a way to understand the version and platform respectively after 2.6 and 3.0, therefore, we only need to write dedicated code for different platforms or unity versions, and then use # If, # else, And # endif to separate these code, then, only the required parts will be edited during compilation, and errors during compilation can be ruled out directly.
Constants used to determine the Platform include:
Unity_editor
Unity_standalone_osx
Unity_dashboard_widget
Unity_standalone_win
Unity_webplayer
Unity_wii
Unity_iphone
Unity_android
Unity_ps3
Unity_xbox360
In the unity Editor, these constants are valid, and do not take effect until the output is complete. For example, in build settings, the platform is switched to Web player, although the game is not output, when the code is determined as the executable area of unity_webplayer, it will be compiled, which greatly increases the convenience of the production period.
The constants used to determine the version include:
Unity_2_6
Unity_2_6_1
Unity_3_0
Unity_3_0_0
Unity_3_1
Unity_3_2
Unity_3_3
Unity_3_4
* Copyright statement: During reprinting, please use hyperlinks to indicate the original source and author information of the article.
* This article is from: unity3d tutorial Manual
* Link to this article: http://www.unitymanual.com/4226.html
Unity distinguishes different platforms