It is necessary that when you click on the UI panel in a variable that will be a counter, recorded the time during which the user holds the finger. When the user releases it, the counter stops increasing. It also increases until it is no longer than 3 seconds or until the user releases the finger. Help write the code that will be responsible for the meter itself. Pressing conditions are optional.

    1 answer 1

    The simplest solution is to check, get information that the user made a touch in the Update() method. And until the user removes the finger from the screen, add the Time.deltaTime value to your time variable variable and ensure that it does not exceed 3, as you wrote in the condition.

    You end up with something like the following:

      private bool touched; private float timer; private void Update() { if (Input.GetMouseButtonDown(0)) { touched = true; return; } if (Input.GetMouseButtonUp(0)) touched = false; if (touched) { timer += Time.deltaTime; if (timer > 3.0f) timer = 3.0f; } }