Double-Tap co-routines not working as intended...

I’ve been trying to implement a simple double-tap co-routine into my project and am having a bit of trouble. I’m trying to make it so that if you’re zoomed out (using a pinch to zoom) you can double tap to move your camera back to its original state. Here’s the code:

void Start()
    {
        if (Input.touchSupported && Application.platform != RuntimePlatform.WebGLPlayer)
            StartCoroutine(TouchListener());
        else
            StartCoroutine(MouseListener());

    }

private IEnumerator TouchListener()
    {
        while (enabled)
        { //Run as long as this is activ
            if (Input.touchCount == 1 && zoomed == true)
                touch = Input.GetTouch(0);
                if (touch.phase == TouchPhase.Ended)
                    yield return TouchEvent();
            yield return null;
        }
    }

    private IEnumerator TouchEvent()
    {
        //pause a frame so you don't pick up the same mouse down event.
        yield return new WaitForEndOfFrame();

        float count = 0f;

        while (count < doubleClickTimeLimit)
        {

            if (Input.touchCount == 1 && zoomed == true)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    DoubleClick();
                    yield break;
                }

                count += Time.deltaTime; // increment counter by change in time between frames
                yield return null; // wait for the next frame
            }
            else
            {
                count += Time.deltaTime; // increment counter by change in time between frames
                yield return null; // wait for the next frame
            }
        }

        SingleClick();
        yield break;
    }

It seems as though when I remove my two fingers from the pinch to zoom, it’s registering the last finger removed as my first tap, and my second co-routine’s timer is not breaking, waiting infinite amounts of time for any touch and firing doubleclick… The zoomed variable is being set by my zooming and is working correctly.

Here is the mouse listener co-routine, which is working correctly if anyone is interested:

private IEnumerator MouseListener()
    {
        while (enabled)
        { //Run as long as this is activ

            if (Input.GetMouseButtonDown(0))
                yield return MouseClickEvent();

            yield return null;
        }
    }

    private IEnumerator MouseClickEvent()
    {
        //pause a frame so you don't pick up the same mouse down event.
        yield return new WaitForEndOfFrame();

        if (zoomed == true)
        {
            float count = 0f;
            while (count < doubleClickTimeLimit)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    DoubleClick();
                    yield break;
                }
                count += Time.deltaTime;// increment counter by change in time between frames
                yield return null; // wait for the next frame
            }
            SingleClick();
            yield break;
        }
    }

Any ideas would be greatly appreciated.

When you set zoomed = true, why not just start your touchlistener(or whatever you are using to detect double tap) then for the double tap? Assuming that is zoomed is being set when a person removes fingers from doing the zoom.

As of now zoomed is being called whenever my orthographicSize is greater than my minimum zoom bounds. I could try something like that though I’m not sure it will stop this “infinite loop” scenario, as I have touch and drag to pan the camera as well, and if it’s still functioning like this it would take my pan touch as first click… I could post the whole code but people don’t seem to like wall-of-codes :smile: