Lens Flare Flash Using Intensity

I need it so that my lens flare will flash when a key is pressed, then turns off when pressed again. I have got this script but it says that MissingFieldException: UnityEngine.LensFlare.intensity

private var on = true;
var timer =0.2;
 
function Start () {
    while (true) {
    	yield WaitForSeconds(0.08);
    	LensFlare.intensity = !LensFlare.intensity;
    	

    }
}
function Update(){

if(Input.GetKeyDown("f2")){
if(on){
LensFlare.intensity =0;
on = false;
}
else {
LensFlare.intensity =1;
on = true;
}
}
}

The LensFlare is a component, so you have to get access to a specific LensFlare component on a specific object using GetComponent(). You cannot access a LensFlare through the class. In addition there is no ‘intensity’ variable on a LensFlare. There is a ‘brightness’ variable. That variable is a float, so you cannot use it the way you are trying to do in line 7. Here is a quick rewrite of your code. Attach it to the game object that has a LensFlare component.

private var on = true;
var timer = 0.2;
var lensFlare : LensFlare;
 
function Start () {
    lensFlare = GetComponent(LensFlare);

    while (true) {
        yield WaitForSeconds(0.08);
        lensFlare.brightness = 0.0;
        on = false;
        yield WaitForSeconds(0.08);
        lensFlare.brightness = 1.0;
        on = true;
    }
}

function Update() {
 
    if(Input.GetKeyDown("f2")){
        on = !on;
        lensFlare.brightness = (on) ? 1.0 : 0.0;
    }
}