- Home /
Question by
KateHassan · Aug 27, 2018 at 02:13 PM ·
timetimerif-statementswhile
start timing when value is reached
Hello everyone :) 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 :)
Comment
Best Answer
Answer by Hellium · Aug 27, 2018 at 02:24 PM
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");
}
Your answer
Follow this Question
Related Questions
How to add a cooldown sort of thing. 1 Answer
Minute Timer Issue 1 Answer
Game Timer help needed 2 Answers
How to make a timer read to the .001 of a second 2 Answers
Timer running down too quickly 1 Answer