Challenge - 5 Problems
Platform Pro in Unity
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of this platform check code?
Consider this Unity C# script snippet that checks the platform using preprocessor directives and prints a message. What will be printed if the game runs on an Android device?
Unity
using UnityEngine; public class PlatformCheck : MonoBehaviour { void Start() { #if UNITY_ANDROID Debug.Log("Running on Android"); #elif UNITY_IOS Debug.Log("Running on iOS"); #else Debug.Log("Running on another platform"); #endif } }
Attempts:
2 left
💡 Hint
Look at the preprocessor directives and which one matches Android.
✗ Incorrect
The #if UNITY_ANDROID directive compiles the code inside only when building for Android. So the Debug.Log prints "Running on Android" on Android devices.
❓ Predict Output
intermediate1:30remaining
What does this code print on Windows standalone build?
Given this Unity C# code snippet, what will be printed when running on a Windows standalone build?
Unity
using UnityEngine; public class PlatformMessage : MonoBehaviour { void Start() { if (Application.platform == RuntimePlatform.WindowsPlayer) { Debug.Log("Windows Standalone"); } else { Debug.Log("Other Platform"); } } }
Attempts:
2 left
💡 Hint
Check the Application.platform property and the RuntimePlatform enum.
✗ Incorrect
Application.platform returns the current platform. On Windows standalone builds, it equals RuntimePlatform.WindowsPlayer, so it prints "Windows Standalone".
🔧 Debug
advanced2:00remaining
Why does this platform-specific code cause a compile error?
This Unity C# script uses platform-specific code but causes a compile error. Identify the cause.
Unity
using UnityEngine; public class PlatformBug : MonoBehaviour { void Start() { #if UNITY_IOS Debug.Log("iOS platform"); #elif UNITY_ANDROID Debug.Log("Android platform"); #else Debug.Log("Other platform"); #endif #if UNITY_EDITOR Debug.Log("Editor mode"); #endif #if UNITY_WIN Debug.Log("Standalone build"); #endif } }
Attempts:
2 left
💡 Hint
Check Unity's official list of valid platform defines.
✗ Incorrect
UNITY_WIN is not a valid preprocessor symbol. The correct symbols are UNITY_STANDALONE_WIN, UNITY_STANDALONE_OSX, or UNITY_STANDALONE_LINUX. Using UNITY_WIN causes a compile error.
📝 Syntax
advanced2:00remaining
Which option correctly uses platform-specific code to include a method only on iOS?
You want to include a method called ShowIosAlert() only when building for iOS. Which code snippet correctly uses preprocessor directives?
Attempts:
2 left
💡 Hint
Preprocessor directives can wrap entire methods to exclude them from compilation.
✗ Incorrect
Option A wraps the entire method with #if UNITY_IOS ... #endif, so the method only exists in iOS builds. Option A compiles the method always but conditionally compiles the body, which can cause errors if called on other platforms. Option A includes the method always and has an else branch. Option A uses UNITY_IPHONE which is deprecated; UNITY_IOS is correct.
🚀 Application
expert3:00remaining
How to implement platform-specific file path handling in Unity?
You want to save a file in a platform-appropriate location in Unity. Which approach correctly handles platform-specific file paths?
Attempts:
2 left
💡 Hint
Unity provides special paths that adapt to each platform's file system.
✗ Incorrect
Application.persistentDataPath gives a safe, writable folder on all platforms. You can append platform-specific subfolders inside #if directives to organize files. Hardcoded absolute paths are unreliable and may cause permission issues. Application.dataPath is read-only on some platforms. Environment.GetFolderPath is not reliable across all Unity platforms.