0
0
Unityframework~10 mins

Platform-specific settings in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the current platform is Android.

Unity
if (Application.platform == [1]) {
    Debug.Log("Running on Android");
}
Drag options to blanks, or click blank then click option'
ARuntimePlatform.WindowsPlayer
BRuntimePlatform.IPhonePlayer
CRuntimePlatform.Android
DRuntimePlatform.OSXPlayer
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong platform enum like iPhonePlayer or WindowsPlayer.
Forgetting to use 'RuntimePlatform.' prefix.
2fill in blank
medium

Complete the code to execute platform-specific code for iOS.

Unity
#if [1]
Debug.Log("Running on iOS");
#endif
Drag options to blanks, or click blank then click option'
AUNITY_EDITOR
BUNITY_IOS
CUNITY_STANDALONE_WIN
DUNITY_ANDROID
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNITY_ANDROID instead of UNITY_IOS.
Confusing editor directives with platform directives.
3fill in blank
hard

Fix the error in the code to correctly detect if the platform is Windows standalone.

Unity
if (Application.platform == [1]) {
    Debug.Log("Running on Windows Standalone");
}
Drag options to blanks, or click blank then click option'
ARuntimePlatform.LinuxPlayer
BRuntimePlatform.WindowsEditor
CRuntimePlatform.OSXPlayer
DRuntimePlatform.WindowsPlayer
Attempts:
3 left
💡 Hint
Common Mistakes
Using WindowsEditor instead of WindowsPlayer.
Confusing OSXPlayer or LinuxPlayer with Windows.
4fill in blank
hard

Fill both blanks to create a dictionary with platform names as keys and their build symbols as values.

Unity
var platformSymbols = new Dictionary<string, string> {
    {"Android", "[1]"},
    {"iOS", "[2]"}
};
Drag options to blanks, or click blank then click option'
AUNITY_ANDROID
BUNITY_IOS
CUNITY_STANDALONE_WIN
DUNITY_EDITOR
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the build symbols for Android and iOS.
Using editor or Windows symbols instead.
5fill in blank
hard

Fill all three blanks to create a platform check that logs a message for Android, iOS, or Windows.

Unity
switch (Application.platform) {
    case [1]:
        Debug.Log("Android platform");
        break;
    case [2]:
        Debug.Log("iOS platform");
        break;
    case [3]:
        Debug.Log("Windows platform");
        break;
}
Drag options to blanks, or click blank then click option'
ARuntimePlatform.Android
BRuntimePlatform.IPhonePlayer
CRuntimePlatform.WindowsPlayer
DRuntimePlatform.LinuxPlayer
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong enums like LinuxPlayer for Windows.
Mixing up Android and iOS enums.