How many frames have passed since i pressed space?

Hi
I want to know how many frames have been passed since ‘Space’ was pressed?

In detail:
When space is pressed and released, a variable should start storing #frames passed since space was last pressed.

Good day.

Why you want this? every frame can have different duration… And in diferents pc even more…

By anyway, you know Update is executed once every frame, so just make a counter on Update, witha

int counter;

void Update()
{
counter++;
}

And you will have the number of frames.

Bye

private int lastFrame ;

public int FramesCountSinceSpacePress
{
    get { return Time.frameCount - lastFrame ; }
}

private void Update()
{
    if( Input.GetKeyDown( KeyCode.space ) )
    {
        Debug.Log( "Space is being pressed !" ) ;
        lastFrame = Time.frameCount ;
    }
    else
    {
        Debug.Log( "Number of frames since space has been pressed = " + FramesCountSinceSpacePress ) ;
    }
}

bool start;
int k; // #frames since ‘O’ was pressed

void Update () 
{
		if (Input.GetKeyUp (KeyCode.O))       // 'O' to reset & stop the counter
			{	start = true;	k = 0;		}
		if (Input.GetKeyUp (KeyCode.P))     // 'P' to stop the counter
			start = false;
		if (start) 
			{
				print (k);     // #frames since 'O' was pressed latest
				k++;
}

Sorry I didn’t use space for activation but this is also working :slight_smile: