Search Unity

  1. Dismiss Notice
  2. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  3. Dismiss Notice

Mobile Detect Device Screen

Discussion in 'Scripting' started by cultzone, Sep 8, 2020.

  1. cultzone

    cultzone

    Joined:
    Oct 20, 2019
    Posts:
    37
    Hi everyone!

    We re back to ask another trick to make detection on mobile device to let window screen so mor confortable to user:

    void Update()
    {
    if (Pressed)
    {
    if (PointerId >= 0 && PointerId < Input.touches.Length)
    {
    TouchDist = Input.touches[PointerId].position - PointerOld;
    PointerOld = Input.touches[PointerId].position;
    }
    else
    {
    TouchDist = new Vector2(Input.mousePosition.x, Input.mousePosition.y) - PointerOld;
    PointerOld = Input.mousePosition;
    }
    }
    else
    {
    TouchDist = new Vector2();
    }
    }
     
    Last edited: Sep 15, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    15,513
    cultzone likes this.
  3. cultzone

    cultzone

    Joined:
    Oct 20, 2019
    Posts:
    37
unityunity