How to make an IF statement check for a set amount of time,Make an IF statement check for a range of time

Does anyone know how to make an if statement check its conditions for a set amount of time?

You can have the if statement inside a for loop

for ( int i = 0; i < amountOfTime; i++)
{
     if (condition)
     {
     }
}

Or if you want to have it check for 10 seconds instead of amount of times,

float timer = 10f;

void Update()
{
   timer -= Time.deltaTime;
   if (yourCondition && timer <= 0)
   {
   }
}

Hi, I have a same problem
In my case I want to verify values detected in real-time for 3 seconds, if they are for three seconds inside a range that I previously set, unity activates an gameobject inside the scenes.

This is the code that I already tried but it doesn’t change after 3 seconds ( maybe because it’s not inside the void update )

private void ReadValue(int[][] packageOfData, int chnIndex)
    {
        for (int i = 0; i < packageOfData.Length; i++)
        {

           // First stage condition
           if (packageOfData_[chnIndex] < 800 && packageOfData*[chnIndex] > 400)*_ 

{
countTime += Time.deltaTime;
}

else
{
countTime = 0.0f;
}

if (countTime >= RequiredTime)
{
if (Aura != null)

{
Aura.SetActive(false);
}

if (AuraGlow != null)

{
AuraGlow.SetActive(false);
}

if (DirectionalLight != null)
{
DirectionalLight.transform.rotation = Quaternion.Slerp(point0.rotation, pointA.rotation, timeCount);
timeCount = timeCount + Time.deltaTime;
}

}
}
}