Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

When to show UI buttons for game control?

Discussion in 'Android' started by sladetheleveller, Feb 20, 2021.

  1. sladetheleveller

    sladetheleveller

    Joined:
    Feb 20, 2021
    Posts:
    3
    Hi, I'm quite new to Unity game development and I'm sure this question has been asked before but I can't seem to find one.

    I've created a proof-of-concept for a game I'd like to write and I have just added UI buttons so that the game can be played on my android phone.

    What I want to do now it switch the UI buttons on/off depending on whether they are needed or not.

    What's the best way to do this? I can see that there are compiler directives that can be used to identify the platform that it is running on. Are these what are normally used to tell whether virtual buttons need to be displayed ie UNITY_IOS and UNITY_ANDROID would show the buttons but UNITY_STANDALONE would not, or is there a better way such as detecting whether a keyboard is present?
     
  2. sladetheleveller

    sladetheleveller

    Joined:
    Feb 20, 2021
    Posts:
    3
    Is there really no one out there who can provide some advice?
     
  3. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    I wouldn't recommend using defines unless necessary, better use https://docs.unity3d.com/ScriptReference/Application-platform.html, since defines hide compilation errors on platforms where define is not defined.

    As you said there are various to achieve what you described above, alternatively you can leave this up to user to decide, like having few buttons in the begining (which can be both touched or clicked by mouse), where users selects control mapping.
     
  4. sladetheleveller

    sladetheleveller

    Joined:
    Feb 20, 2021
    Posts:
    3
    Thank you. I didn't know about the Application.Platform property. I'm going to give it a look now.