Search Unity

check if my device is movile or desktop WebGL

Discussion in 'Scripting' started by danchavil, Jan 4, 2019.

  1. danchavil

    danchavil

    Joined:
    Jul 12, 2018
    Posts:
    32
    Hello,

    i have a project, when the user enter to my application i need to verify if it is a mobile device or desktop.

    because i have two diferent functionalities. one for touch devices and other for click with mouse

    is this possible?

    thanks everyone
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,740
    Application.platform will give you some of this.

    https://docs.unity3d.com/ScriptReference/Application-platform.html

    There are other 'capabilities' helpers in classes like Input, such as .mousePresent and .touchesSupported, etc.

    Use caution though: I think .mousePresent might be true even on mobile, as it 'down-munges' all your touches into a single mouse touch.

    I have a MicroTouch class that I wrote to make this transparent between platforms. It's inside my proximity_buttons project and I think you pretty much only need that one .cs file to use it in your project. Source code here:

    https://bitbucket.org/kurtdekker/proximity_buttons

    Look for the file MicroTouch.cs and there's obviously button and joystick code in there that uses it.