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.

ut.Core2D.Input.isTouchSupported() fun

Discussion in 'Project Tiny' started by reallyhexln, May 17, 2019.

  1. reallyhexln


    Jun 18, 2018
    Hi guys!

    Please note, ut.Core2D.Input.isTouchSupported() function might return false for mobile browsers while you didn't made the first tap on the screen.

    Yes, it was described in the jsdoc:
    Code (JavaScript):
    1. /** Returns true if the current device produces touch input responses.
    2.     This value may not be accurate until a first touch occurs.*/
    Anyway, please paid attention to that. I spent some time to determine why I get unexpected behavior on mobile browsers at the first game screen.

    Because I target my game to Chrome-based browsers only, I use the following alternative for ut.Core2D.Input.isTouchSupported() function:
    Code (JavaScript):
    1. export function isTouchSupported(): boolean {
    2.     return ('ontouchstart' in window);
    3. }
    I'm not sure it will be work for all other modern browsers. If you need true cross-browser solution, please check SO.
    boringName, Pakor and Zionisias like this.