Search Unity

Mobile Controls

Discussion in '2D' started by Carson365, Nov 17, 2017.

  1. Carson365

    Carson365

    Joined:
    Nov 8, 2017
    Posts:
    42
    Hello!
    So I am making my first game that I'm planning to post on ios/android. I'm wondering how I can make controls in the game for the phone, but also be able to test it on Unity.
    I am a beginner so I don't quite know how this stuff works yet.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    There's no magic to it; make up a control scheme for the touch screens, and if that's hard to test on the desktop with a mouse, then add alternate keyboard controls. If you want, you can even leave those in as a hidden feature for anybody who happens to have a Bluetooth keyboard on their iOS/Android device.
     
  3. Kaart

    Kaart

    Joined:
    Jul 31, 2017
    Posts:
    62
    You can use platform dependent compilation to use 2 different control schemes depending on your platform https://docs.unity3d.com/Manual/PlatformDependentCompilation.html. A small example would be:

    Code (CSharp):
    1. public class ControlExample : MonoBehaviour {
    2.  
    3.     private void Update () {
    4.  
    5.     #if UNITY_EDITOR // If testing your code in Unity this code would run.
    6.         // Your Unity controls go here
    7.  
    8.     #else  // Otherwise this code would run.
    9.         // Your mobile controls go here
    10.     #endif
    11.     }
    12. }
     
    JoeStrout likes this.
  4. Carson365

    Carson365

    Joined:
    Nov 8, 2017
    Posts:
    42
    Thanks for both of your answers. I also found a tutorial on Unity for mobile so I will try theses out.
    Thanks!