📖 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
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
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
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
Hint
Use Debug.Log(platformMessage); to print the message.
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
Step 1: Understand platform-specific settings
Platform-specific settings allow customizing game behavior for different devices.
Step 2: Identify the main goal
The goal is to ensure the game works well on all targeted platforms.
Final Answer:
To make the game work well on different devices -> Option C