Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

ut.Core2D.Input.isTouchSupported() fun

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

  1. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    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.