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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Differentiate to 'hold' and 'tap' (Touch)

Discussion in 'Scripting' started by borjahen, May 27, 2015.

  1. borjahen

    borjahen

    Joined:
    May 27, 2015
    Posts:
    1
    Hi,

    First I want to apologize if I speak bad English. I will try to explain my question well so that you can understand.

    I have a boxing game for Android and I would like to differentiate the 'hold' and 'tap' screen mobile phone.

    - If 'tap' makes an interpolation attack
    - If 'hold' makes an interpolation for cover

    * I made the interpolations with Vector Lerp but I wonder how to differentiate between 'hold' and 'touch'

    Thanks community.
     
  2. legendz25

    legendz25

    Joined:
    May 30, 2014
    Posts:
    17
  3. AzariDeveloper

    AzariDeveloper

    Joined:
    Dec 4, 2019
    Posts:
    1
    public RectTransform objectToHold;
    public Image fillImage;
    public float holdDuration = 1f;

    void Update()
    {
    if(Input.touchCount > 0)
    {
    Touch touchInfo = Input.GetTouch(0);
    if(touchInfo.phase == TouchPhase.Stationary && RectTransformUtility.RectangleContainsScreenPoint (objectToHold ,touchInfo.position) )
    {
    print("is pressing and holding");
    float remainingDuration = holdDuration -= Time.deltaTime;
    fillImage.fillAmount = remainingDuration / holdDuration;

    if (holdDuration <= 0)
    {
    //Do Stuff when timer is finished
    }

    }
    }
    }
     
    JIM_STOCKHOLM and jhinshots like this.