Bird
Raised Fist0
Unityframework~20 mins

Platform-specific settings in Unity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Platform Pro in Unity
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1: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
    }
}
ARunning on iOS
BRunning on Android
CRunning on another platform
DNo output, code will not compile
Attempts:
2 left
💡 Hint
Look at the preprocessor directives and which one matches Android.
❓ Predict Output
intermediate
1: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");
        }
    }
}
AWindows Standalone
BOther Platform
CNo output
DRuntime error
Attempts:
2 left
💡 Hint
Check the Application.platform property and the RuntimePlatform enum.
🔧 Debug
advanced
2: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
    }
}
AUsing multiple #if directives in one method causes syntax errors.
BThe code is correct and compiles without errors.
CUNITY_EDITOR cannot be used with other platform directives in the same method.
DUNITY_WIN is not a valid preprocessor directive, causing a compile error.
Attempts:
2 left
💡 Hint
Check Unity's official list of valid platform defines.
📝 Syntax
advanced
2: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?
A
#if UNITY_IOS
public void ShowIosAlert() {
    Debug.Log("iOS Alert");
}
#endif
B
public void ShowIosAlert() {
#if UNITY_IOS
    Debug.Log("iOS Alert");
#endif
}
C
public void ShowIosAlert() {
#if UNITY_IOS
    Debug.Log("iOS Alert");
#else
    Debug.Log("Not iOS");
#endif
}
D
public void ShowIosAlert() {
#if UNITY_IPHONE
    Debug.Log("iOS Alert");
#endif
}
Attempts:
2 left
💡 Hint
Preprocessor directives can wrap entire methods to exclude them from compilation.
🚀 Application
expert
3: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?
AUse hardcoded absolute paths like "C:/MyGame/" for Windows and "/Documents/MyGame/" for iOS inside #if directives.
BUse Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) for all platforms without Unity-specific paths.
CUse Application.persistentDataPath for all platforms and append platform-specific subfolders using #if directives.
DUse Application.dataPath for saving files on all platforms without any platform checks.
Attempts:
2 left
💡 Hint
Unity provides special paths that adapt to each platform's file system.

Practice

(1/5)
1. What is the main purpose of using platform-specific settings in Unity?
easy
A. To disable all graphics features
B. To increase the game's file size
C. To make the game work well on different devices
D. To make the game run only on Windows

Solution

  1. Step 1: Understand platform-specific settings

    Platform-specific settings allow customizing game behavior for different devices.
  2. Step 2: Identify the main goal

    The goal is to ensure the game works well on all targeted platforms.
  3. Final Answer:

    To make the game work well on different devices -> Option C
  4. Quick Check:

    Platform-specific settings = device compatibility [OK]
Hint: Think about device compatibility and performance [OK]
Common Mistakes:
  • Confusing platform-specific settings with increasing file size
  • Assuming settings limit the game to one platform
  • Believing settings disable features globally
2. Which of the following is the correct way to write platform-specific code for Android in Unity?
easy
A. #if UNITY_ANDROID // Android code #endif
B. #if ANDROID // Android code #endif
C. #if PLATFORM_ANDROID // Android code #endif
D. #if UNITY_MOBILE // Android code #endif

Solution

  1. Step 1: Recall Unity platform symbols

    Unity uses symbols like UNITY_ANDROID for Android platform checks.
  2. Step 2: Match the correct syntax

    #if UNITY_ANDROID is the correct directive for Android-specific code.
  3. Final Answer:

    #if UNITY_ANDROID // Android code #endif -> Option A
  4. Quick Check:

    Use UNITY_ANDROID for Android platform [OK]
Hint: Use UNITY_ prefix for platform symbols [OK]
Common Mistakes:
  • Using incorrect symbols like ANDROID or PLATFORM_ANDROID
  • Assuming UNITY_MOBILE covers Android specifically
  • Missing #endif to close the directive
3. What will be the output when running this Unity C# code on iOS platform?
#if UNITY_IOS
Console.WriteLine("Running on iOS");
#else
Console.WriteLine("Running on other platform");
#endif
medium
A. Running on other platform
B. No output
C. Compilation error
D. Running on iOS

Solution

  1. Step 1: Check platform directive

    The code uses #if UNITY_IOS, which is true on iOS platform.
  2. Step 2: Determine executed code

    Since UNITY_IOS is defined, it prints "Running on iOS".
  3. Final Answer:

    Running on iOS -> Option D
  4. Quick Check:

    UNITY_IOS true prints iOS message [OK]
Hint: Match platform symbol with current device [OK]
Common Mistakes:
  • Confusing UNITY_IOS with UNITY_IPHONE
  • Expecting else block to run on iOS
  • Thinking code causes compilation error
4. Identify the error in this Unity C# code snippet for platform-specific compilation:
#if UNITY_STANDALONE
Debug.Log("Standalone platform");
#else
Debug.Log("Other platform");
medium
A. Missing #endif to close the #if directive
B. Wrong platform symbol UNITY_STANDALONE
C. Debug.Log cannot be used in platform directives
D. No error, code is correct

Solution

  1. Step 1: Check #if directive syntax

    The code starts with #if but does not have a matching #endif.
  2. Step 2: Understand preprocessor rules

    Every #if must be closed with #endif to avoid compilation errors.
  3. Final Answer:

    Missing #endif to close the #if directive -> Option A
  4. Quick Check:

    #if must end with #endif [OK]
Hint: Always close #if with #endif [OK]
Common Mistakes:
  • Assuming UNITY_STANDALONE is invalid
  • Thinking Debug.Log is disallowed inside #if
  • Ignoring missing #endif causes errors
5. You want to write code that runs only on Windows or macOS but not on mobile platforms. Which directive correctly achieves this in Unity?
hard
A. #if UNITY_STANDALONE // code #endif
B. #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX // code #endif
C. #if UNITY_ANDROID || UNITY_IOS // code #endif
D. #if UNITY_MOBILE // code #endif

Solution

  1. Step 1: Identify platforms to include

    Windows and macOS correspond to UNITY_STANDALONE_WIN and UNITY_STANDALONE_OSX.
  2. Step 2: Combine platform symbols correctly

    Use logical OR (||) to include both platforms in one directive.
  3. Final Answer:

    #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX // code #endif -> Option B
  4. Quick Check:

    Use || to combine Windows and macOS platforms [OK]
Hint: Use || to combine multiple platforms [OK]
Common Mistakes:
  • Using UNITY_STANDALONE alone includes all standalone platforms
  • Confusing mobile symbols with desktop platforms
  • Using && instead of || for platform combination
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard