- Home /
Is there a way to automatically detect if a game is running on a Mac or PC?
I'm working on a game that's designed for controllers and the solution we found for connecting 360 controllers to a Mac has the buttons mapped differently than on the PC. This isn't too big an issue when testing the game as we can just swap in the Input files, but is there a way to automatically detect which operating system the game is running on?
Answer by fafase · Jun 06, 2013 at 07:27 AM
You may use answers from BiG or you can also use macros.
http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html
This way you can wrap code that are specific to a platform and the rest is ignored at compilation. You then get a slightly smaller exe file since it does not include all the code from the platform you would have never used.
Answer by BiG · Jun 06, 2013 at 06:55 AM
Yes, there is. Just use Application.platform.
From the documentation's example that I've linked:
function Start () {
if (Application.platform == RuntimePlatform.WindowsPlayer)
print ("Do something special here!");
}