Invicibilty frames

when my character gets hurt i want him to flicker for a few seconds but, how do i make the game wait before doing something like the wait x seconds block in scratch. here is my current code:

void invisFrames()
{
godMode = true;
rb.AddForce(transform.up * backForce);
while (timer < 40)
{
SR.enabled = false;
timer += 1 * Time.deltaTime;
SR.enabled = true;
timer += 1 * Time.deltaTime;
}
}

You could use Coroutines.

using System.Generics;

void Start(){

StartCoroutine(Invencibility())

}

IEnumerator Invencibility(){
godMode= true;
rb.AddForce(transform.up backForce);
yield return WaitForSeconds(timeToWait);
godMode= false;

}