- Home /
photocamera flash
hello i have a script for a photo flash. But the script is not good. here is the script:
sec : float = 0.1f;
function update () {
//if pressed mouse1 the light will go on for 0.1 second and then go off
if (Input.GetKeyDown(mouse1));
light.intensity = "1.0";
yield.WaitForSeconds = sec;
light.intensity = "0.0";
can anyone help me?
Answer by screenname_taken · Aug 26, 2014 at 11:20 AM
You can't have yield wait for secs in the update loop.
Instead make a function on it's own, put the light code you did in there, and call that function under the if statement.
ALSO and this is a bigger issue, you have a ";" after the if statement. Take it off. Also, because you didnt' use { } at the if statement, only the first line after it is called if the statement is checked. the rest will run anyway. The check should be GetMouseBtnDown()
Code should be
function Update(){
if (Input.GetMouseButtonDown(0)){
LightMe();
}
}
function LightMe(){
light.intensity = 1.0;
yield WaitForSeconds(sec);
light.intensity = 0.0;
}
Changed stuff from @tanoshimi
intensity is a float, not a string. light.intensity = 1.0;
And in the original code, update() should be Update(). ;)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
BCE0049 error with network script 0 Answers
Weird thing with my script :/ 1 Answer