Please help with GetMouseButtonDown

Hello All,

I am having a problem and my question keeps getting rejected through Unity Answers. I am trying to get some code that on the first click of Lft Mouse button everything slows down, if you click Lft Mouse again with in 4 seconds you teleport to the position you clicked. I have the slow time working and the teleport working, just cannot get the two clicks to happen separately. The only way I can think of doing it is an if(GetMouseButtonDown) function with another if(GetMouseButtonDown) inside of it.This is what I have, please any help would be greatly appreciated i have been stuck on this for going on three days now.

    IEnumerator JumpWait()
    {
        yield return new WaitForSeconds(.5f);
        Player.transform.position = new Vector3(tx, ty, tz);
        yield return new WaitForSeconds (.25f);
        particle.particleEmitter.enabled = false;
    }

    IEnumerator NoJumpWait()
    {
        yield return new WaitForSeconds (2f);
        Time.timeScale = 1f;
    }


    void Update()
    {
        if(Input.GetMouseButtonDown(0)) 
        {
            Time.timeScale = .5f;
            Debug.Log("Mouse Click 1");

            if(Input.GetMouseButtonDown(0))
            {
                Debug.Log ("Mouse Click 2");
                animator.SetBool("Jump", true);
           
                RaycastHit hitInfo;
                Ray rayOrigin = Camera.main.ScreenPointToRay (Input.mousePosition);

                if (Physics.Raycast (rayOrigin, out hitInfo, maxDist))
                {
                    tx = hitInfo.point.x;
                    ty = hitInfo.point.y;
                    tz = hitInfo.point.z;
                    particle.particleEmitter.enabled = true;
                    StartCoroutine(JumpWait());
                }
                StartCoroutine (NoJumpWait());
            }
        }
    }

    }

Create a boolean that reset after 4 seconds. So you want to do is this:

Event: Left Click

Pseudo Code:
// Variables needed
bool isTimeSlowed = false;
float elapsedTime = 0.0f;
float doubleClickTime = 4.0f;

// Logical Checks
1.) if(isTimeSlowed == false) then slow down time and set isTimeSlowed = true
2.) if(isTimeSlowed == true) then check if(elapsedTime < doubleClickTime) jump
3.) if(elapsedTime < doubleClickTime) increment elapsedTime += Time.deltaTime
4.) if(elapsedTime > doubleClickTime) set elapsedTime = 0.0f isTimeSlowed = false;

Does this make sense?

that makes sense i will get back in a little while, im gonna try it out

If you get stuck let me know and I can code something up for you really quick :slight_smile:

Nice work. There’s no need for a coroutine for something this simple, haha.