start timing when value is reached

Hello everyone :slight_smile:
I would like to start timing when a value I have goes under a certain threshold.
So like:

if value < 10 for longer than 1 second, take screenshot.

or

while value < 10

start timer

if timer > 1 second

take screen shot

(???)

any help is appreciated :slight_smile:

public int value ;
public int threshold;
private float timer ;
private bool functionCalled ;

private void Update()
{
    if( value < threshold )
    {
         timer += Time.deltaTime ;
         if( timer > 1 && !functionCalled )
         {
              Foo() ;
              functionCalled = true ;
         }
    }
    else
     {
          timer = 0 ;
          functionCalled = false ;
     }
}


private void Foo()
{
     Debug.Log("Take screenshot");
}