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.
Answer by Hellium · Jun 23, 2018 at 12:54 PM
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.Get$$anonymous$$eyUp ($$anonymous$$eyCode.O)) // 'O' to reset & stop the counter
{ start = true; k = 0; }
if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.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 :)
Answer by tormentoarmagedoom · Jun 22, 2018 at 09:20 PM
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
Your answer
Follow this Question
Related Questions
Frame Base Jump Loop 0 Answers
Coyote Timer Gives Double Jump Frames. 1 Answer
Breaking out of problem code 0 Answers
Can I animate to 100/ths of a second 0 Answers
Custom Animation Editor 0 Answers