- Home /
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
}
}
Answer by liszto · Feb 17, 2013 at 01:08 AM
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 : http://docs.unity3d.com/Documentation/ScriptReference/Light.html
Answer by Sargoryon · Feb 17, 2013 at 01:15 AM
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 :)
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 :)
edit: you can use the first one for a flash light
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Browser-based JavasScript to Flash communication 0 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
JavaScript --> Unity Flash Build 2 Answers
Flash to html communication 1 Answer