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
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

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.