- Home /
I have a parsing error. and yes, I am a noob.
Line 35,1
using UnityEngine;
using System.Collections;
public class FlashLightController : MonoBehaviour
{
public Light flashlightObject;
void Start ()
{
bool flashlightObject = false;
}
void Update ()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
if(flashlightObject.enabled == false)
{
bool flashlightObject = true;
}
else
{
flashlightObject = enabled = false;
}
}
}
}
}
}
Answer by rutter · Sep 24, 2014 at 02:05 AM
You have unbalanced {}
braces. Generally speaking, each {
opening brace should have a matching }
closing brace. It's easier to keep track of that if your code is organized (which yours mostly is).
Lines 35 and 36? They're extra braces you don't need. Delete them.
After that, you'll need to fix lines 11, 21 and 27. You might be a little confused about how you set the enabled
property:
flashlightObject.enabled = false; //example
You can also toggle a boolean value with the !
operator, also called "logical NOT":
flashlightObject.enabled = !flashlightObject.enabled; //toggle
Just one addition, declaring a variable inside {} braces will make that variable available inside those {} braces only. And you are actually doing it on your line #11 and line #21 where @rutter has actually provided you with the correct logic which does not care for this issue.
But just so you know, if you want to use a variable inside from any method in your script or even from another scripts then you should declare them where you have declared your
public Light flashlightObject;
where you can list all your variable declarations below current declaration. Also to be able to access that variable from other scripts it should be public.
Your answer
Follow this Question
Related Questions
Enter Trigger, display Text, then delete object 1 Answer
Parsing error CS8025 0 Answers
NullReferenceException 3 Answers
CS8025 ERROR : Camera Script 1 Answer
error CS8025: Parsing error in C# code 3 Answers