How to make a point light which flashes when a key is pressed?

For a cannon. I have tried somewhere along the lines of this:

var muzzleFlash : GameObject;

function Update() {
	
	if (Input.GetKeyDown("D")) {
		//light flash code is here
	}
}

You can do this simply like this :

var muzzleFlash : GameObject;
 
function Update() {
 
    if (Input.GetKeyDown("D")) {
       //light flash code is here
       !linkedLight.enabled = linkedLight.enabled;
    }
}

But what do you mean exactly by flash ? Or you can change the value : Light.intensity

==> Documentation here : Unity - Scripting API: Light

simply use the light.intensity

ie:

var islighton = 0

function Update() {

if (islighton == 0 && Input.GetKeyDown ("D")) {

light.intensity = 1;
}
else if (islighton == 1 && Input.GetKeyDown("D")) {

light.intensity = 0;
}
}

You don’t even need the MuzzleFlash variable, simply attach this to the light and it will work and you can also toggle between on and off :slight_smile:

if you want it to just flash when key is pressed simply do this:

function Update() {

if (Input.GetKeyDown("D")) {
light.intensity = 1;
}

else
{
light.intensity = 0;
}
}

i think it’s something like that, i can’t test this second code now, good luck :slight_smile:

edit: you can use the first one for a flash light