How can i Identified the Key is Pressed Multiple Times (608064)

Hi All

I am new bie to unity. In my project i have to press space bar multiple time.

for eg: if first time space bar pressed it should display “1st” and second time pressed “2nd timepressed” and third time

3 rd Pressed.all should complete within 1 minutes. after 1 minutes the timer should reset.

how can i do it.

I have code for first time . I don’t know how to do it for second and third time display?

if (Input.GetKeyDown (KeyCode.Space)) { print (“I st time Pressed”); }

using UnityEngine;

public class MyCounter : MonoBehaviour
{
    public int count;

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            ++count;
        }

        switch (count)
        {
            case 1:
                Debug.Log("1st time!");
                break;

            case 2:
                Debug.Log("2nd time!!");
                break;

            case 3:
                Debug.Log("3rd time!!!");
                break;
        }
    }
}
1 Like

you’ll need to add a couple of things to @ung 's example to get the time element:

a variable to store the start time of the “minute” when count =0, and check to see if the current time is greater than startTime + 1 at which point reset the count to 0.

Thanks Ung and leftyRighty…Actually i have problem with timer. could any one help me. .
thanks in advance…

using UnityEngine;

public class MyCounter : MonoBehaviour
{
    public int count;

    private float t;

    private void Update()
    {
        t += Time.deltaTime;

        if (t >= 60)
        {
            count = 0;
            t -= 60;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            ++count;
        }

        switch (count)
        {
            case 1:
                Debug.Log("1st time!");
                break;

            case 2:
                Debug.Log("2nd time!!");
                break;

            case 3:
                Debug.Log("3rd time!!!");
                break;
        }
    }
}

Hi all I am new bie to unity .
How can i set the timer. in the above code.

in 3 seconds 3 clicks happens "3 msg " should displayed.

after that time and key should reset. (key should counts from 0-4)

in 4 seconds 4 times clicks " 4 msg " should displayed.

how can i do it…