- Home /
Question by
Thunderturtle712 · Apr 21, 2014 at 08:49 PM ·
flashlighthorror
Help with flashlight script.
I was making a code to make a toggable flashlight. this is what i did and this is the error i got.
Assets/Scripts/Flashlight.js(1,1): BCE0044: expecting EOF, found 'on'.
here is my script
on : boolean = false; //this is the line it said
function Update()
{
if(Input.GetKeyDown(KeyCode.F))
on = !on;
if(on)
light.enabled = true;
if(!on)
light.enabled = false;
}
Comment
Add my two cents:
#pragma strict
function Update() {
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.F))
light.enabled = !light.enabled;
}
Answer by Kumo-Kairo · Apr 21, 2014 at 08:58 PM
var on : boolean = false;
It seems you've missed a var part of your variable definition
Answer by aceX · Apr 21, 2014 at 09:16 PM
Works just fine... don't know much about JavaScript though lol
var flashOn = false;
function Update ()
{
if(Input.GetKeyDown(KeyCode.F))
flashOn = !flashOn;
if(flashOn)
light.enabled = true;
else if(!flashOn)
light.enabled = false;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613143247im_/https://answers.unity.com/themes/thub/images/avi.jpg)