Coding for Multiple Platforms

Coding for Multiple Platforms

Certain platforms require specific function calls that are unique to that particular system. If you are developing a game for multiple platforms, you need a way to tell the compiler not to include the code for non-compatible platforms. Unity provides a number of platform defines that can be used with preprocessor directives to limit certain blocks of code to specific platforms.

Info

A full list of platform defines is available in the Unity Manual under Scripting > Scripting Overview > Platform Dependent Compilation.

Wii U-Specific Code

If you build for platforms other than the Wii U, calls to the Wii U API will cause errors that will stop your build. You can prevent this by using #if and #endif statements around your Wii U-specific code.

 

#if UNITY_WIIU
    // Wii U-specific code here
#endif

Excluding Code in the Unity Editor

Sometimes you also don't want Wii U code to run when you are testing a Wii U game inside the Unity Editor (testing on the PC). Code for unusable features on the PC (such as for Wii Remote input and sensor data) will not throw errors, so you don't need to give this special attention. However, Wii U-specific networking code will cause problems, so in this case you should set it to only be compiled for when you run it on the devkit. You can do this with the following preprocessor directives.

#if UNITY_WIIU && !UNITY_EDITOR
    // Wii U-specific code here
#endif

 


CONFIDENTIAL