- Home /
How do i properly use Application.platform ?
working on a little mobile game.. and i want to be able to use my desktop keyboard while also being able to use my joystick without creating separate methods? this code below isnt working right. the UNITY_STANDALONE_WIN is grayed out. whats the best way to do this?
Vector2 move = Vector2.zero;
float MoveJoy = variableJoystick.Horizontal;
#if UNITY_IOS
move.x = MoveJoy;
#endif
#if UNITY_STANDALONE_WIN
move.x = Input.GetAxis("Horizontal");
#endif
I don't really get the question. What exactly are you trying to do here. Your title mentions Application.platform, however in your question description you don't even mention it once. Ins$$anonymous$$d you have some code with preprocessor tags. You said you create a mobile game. So I have no idea why you use the windows standalone define here unless you also want to build for windows standalone. You also said you want to use your desktop keyboard. This doesn't make much sense since you talk about a mobile game.
If the question was actually about dual building, once for mobile and once for windows standalone, your above code should work just fine when you create a modile / windows standalone build.
Note that Unity can only be "switched" to one specific target. If you change your build target in your player settings the preprocessor defines will change and the other part will be greyed out.
i appreciate your help, now i get why this isnt working the way i intended.Im simply just trying to use two controls while making my game. Sometimes i dont want to plug my phone in to test and ins$$anonymous$$d i want to use the WASD keys on my computer's keyboard.
Answer by cdauphin · Feb 12, 2020 at 02:22 PM
In Unity, try to change the build target from iOS to Standalone Windows and you'll se the greyed (deactivated) part of the code being activated.
#if UNITY_STANDALONE_WIN
// Windows stuff
#endif
This piece of code is called preprocessing. It tells to the compiler that there is some part of your code that is needed only on some target (i.e : windows). When you're on other target, it won't compile the part of code which is preprocessed.