'Game transfer from PC to Android (Unity)

I have a question. Since I was making my game(2D) in UNITY to work for PC, and now I want to switch platform for ANDROID. So my question is, can I put both controls for pc and android in one script? Like, just to add those codes beneath, or there is some other ways?

I appreciate every help!



Solution 1:[1]

You can use preprocessing directives to use different code for different platforms within the same script.

For example:

#if UNITY_ANDROID
    // Android code here.
#elif UNITY_STANDALONE
    // PC code here.
#endif

When building, Unity compiles only the relevant code for the selected platform and completely ignores the other parts.

enter image description here

Your IDE will also grey out the excluded part in the above code:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guney Ozsan