Switching Light2D intensity on and off Unity3D C#

Trying to have flashing lights like a cop car’s lights. Using Universal RP, I have two spot lights in the scene and want them to turn on and off. Here is the code I tried to piece together.

using UnityEngine;
 using System.Collections;
 using UnityEngine.Experimental.Rendering.Universal;
 
 public class flash :MonoBehaviour {
    
    public Light2D light;
    [SerializeField] float flashTime;
    public bool on;
   
     void Start(){
         on = true;
         flashOn();
     }
 
     void Update(){

     }
     
     private IEnumerator flashOn()
     {
        
          if (on == true)
            {
            light.intensity = 1.0f;
            yield return new WaitForSeconds(flashTime);
            on = false;
            }
            else if (on == false)
            {
            light.intensity = 0.0f;
            yield return new WaitForSeconds(flashTime);
            on = true;
            
            }
     }

 }

Your coroutine doesn’t loop, so it ends after one flash. Also, you could simplify it by doing something like

while(true)
{
    on = !on;
    light.intensity = on? 1f : 0f;
    yield return new WaitForSeconds(flashTime);
}