0
0
Unityframework~30 mins

Platform-specific settings in Unity - Mini Project: Build & Apply

Choose your learning style9 modes available
Platform-specific Settings in Unity
📖 Scenario: You are creating a simple Unity game that behaves differently on Windows and Android platforms. You want to set up platform-specific settings to show a message depending on the platform the game is running on.
🎯 Goal: Build a Unity script that detects the platform at runtime and displays a message specific to Windows or Android.
📋 What You'll Learn
Create a C# script with a string variable for the message
Add a platform check variable
Use an if-else statement to set the message based on platform
Print the message to the Unity Console
💡 Why This Matters
🌍 Real World
Games and apps often need to behave differently on various platforms like Windows, Android, or iOS. Detecting the platform helps customize user experience.
💼 Career
Understanding platform-specific settings is important for Unity developers to create cross-platform games and apps that run smoothly on different devices.
Progress0 / 4 steps
1
Create a string variable for the message
Create a public string variable called platformMessage inside a new C# class called PlatformSettings.
Unity
Need a hint?

Use public string platformMessage; inside the class.

2
Add a platform check variable
Inside the PlatformSettings class, create a private variable called isWindows of type bool and set it to Application.platform == RuntimePlatform.WindowsPlayer.
Unity
Need a hint?

Use private bool isWindows = Application.platform == RuntimePlatform.WindowsPlayer;

3
Set the message based on platform
Inside the Start() method of PlatformSettings, use an if statement with isWindows to set platformMessage to "Running on Windows". Use else to set platformMessage to "Running on Android".
Unity
Need a hint?

Use if (isWindows) { platformMessage = "Running on Windows"; } else { platformMessage = "Running on Android"; } inside Start().

4
Print the platform message
Inside the Start() method, after setting platformMessage, add a line to print it to the Unity Console using Debug.Log(platformMessage);.
Unity
Need a hint?

Use Debug.Log(platformMessage); to print the message.