Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Choosing whether to show touch controls (touchscreen detection?)

Discussion in 'Web' started by caeonosphere, Nov 9, 2023.

  1. caeonosphere

    caeonosphere

    Joined:
    Jul 6, 2017
    Posts:
    4
    Hey all!

    I'm working on a WebGL/HTML5 game that supports both keyboard controls and touch controls via "virtual" onscreen buttons. Since the touch buttons are pretty big and distracting, I'd like to only show them when there's no keyboard present, or when there's a touch screen.

    This approach is almost working:
    Code (CSharp):
    1. bool isIOS = SystemInfo.deviceModel.StartsWith("iP");
    2. bool isAndroid = Application.isMobilePlatform;
    3. bool isMobile = isIOS || isAndroid;
    except for Safari on iPad, specifically. Chrome on iPad works, Safari on iPhone works. It seems that the iPad Safari user agent is identifying it as an OSX desktop, essentially. Is there a way to fix this hole, or even a better way to go about this overall?