0
0
Unityframework~10 mins

Platform-specific settings in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Platform-specific settings
Start: Unity Project
Open Build Settings
Select Platform
Adjust Platform-specific Settings
Apply & Build
Test on Target Platform
End
This flow shows how you pick a platform in Unity, change its settings, then build and test your game for that platform.
Execution Sample
Unity
using UnityEngine;

public class PlatformCheck : MonoBehaviour
{
    void Start()
    {
#if UNITY_IOS
        Debug.Log("Running on iOS");
#elif UNITY_ANDROID
        Debug.Log("Running on Android");
#else
        Debug.Log("Running on another platform");
#endif
    }
}
This code prints a message depending on which platform the game is running on.
Execution Table
StepPlatform SymbolCondition CheckedResultOutput
1UNITY_IOSIs UNITY_IOS defined?No
2UNITY_ANDROIDIs UNITY_ANDROID defined?YesRunning on Android
3ElseNo other platform matchedSkipped
💡 UNITY_ANDROID symbol is defined, so that block runs and others are skipped.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
Output message"""""Running on Android""Running on Android"
Key Moments - 2 Insights
Why does only one Debug.Log run even though there are multiple platform checks?
Because the #if/#elif/#else directives stop checking after the first true condition, as shown in execution_table step 2 where UNITY_ANDROID is true and others are skipped.
What happens if no platform symbol matches?
The #else block runs, printing the default message. This is shown in execution_table step 3 which is skipped here but would run if no symbols matched.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what output is printed at step 2?
ARunning on iOS
BRunning on Android
CRunning on another platform
DNo output
💡 Hint
Check the Output column at step 2 in the execution_table.
At which step does the condition become true and stop further checks?
AStep 2
BStep 3
CStep 1
DNo step
💡 Hint
Look at the Condition Checked and Result columns in execution_table.
If UNITY_IOS was defined instead of UNITY_ANDROID, what would be the output?
ARunning on another platform
BRunning on Android
CRunning on iOS
DNo output
💡 Hint
Refer to the execution_table logic for UNITY_IOS and UNITY_ANDROID conditions.
Concept Snapshot
Platform-specific settings in Unity let you customize builds for iOS, Android, etc.
Use #if UNITY_IOS, #elif UNITY_ANDROID to run code only on certain platforms.
Adjust settings in Build Settings for each platform.
Build and test on the target device to verify.
This helps make your game work well everywhere.
Full Transcript
Platform-specific settings in Unity allow you to customize your game for different devices like iOS or Android. You open Build Settings, pick a platform, change its settings, then build and test. In code, you use #if UNITY_IOS or #elif UNITY_ANDROID to run platform-specific code. Only the first matching condition runs, so only one message prints. If no platform matches, the #else block runs. This helps your game behave correctly on each device.