i have a parsing error on this script

i have a parsing error on this script

heres the error
Assets/scripts/Flashlight.cs(46,9): error CS8025: Parsing error

and this is the afore mentioned script

using UnityEngine;
using System.Collections;

public class Flashlight : MonoBehaviour {

public Light FlashLightObject;
public float Batterypower = 1000.0f;

	
	void Start() 
	{
		FlashLightObject.enabled = false;
	}

	void Update () 
	{
	//on/off
	
	if(Input.GetKeyDown(KeyCode.F))
		{
			if(FlashLightObject.enabled == false){
			
				FlashLightObject.enabled = true;
			}
			else
			{
			FlashLightObject.enabled = false;
			}

				
	//power management 
	
			if (FlashLightObject.enabled == true)
			
			{
			Batterypower -= 1.0f;
			}
	// no power 	
			if (Batterypower <= 0)
			{
				FlashLightObject.enabled = false;
				Batterypower = 0;
			}	
		}	
	}

di i have to many or not enough curly braces

1 Answer

1

It does appear you’re missing some curly braces. I placed it where i think you would like it separating the on/off if statement and the general battery drain and power check:

using UnityEngine;
using System.Collections;

public class Flashlight : MonoBehaviour 
{
	public Light FlashLightObject;
	public float Batterypower = 1000.0f;

	void Start() 
	{
		FlashLightObject.enabled = false;
	}

	void Update () 
	{
		//on/off
		if(Input.GetKeyDown(KeyCode.F))
		{
			if(FlashLightObject.enabled == false)
			{
				FlashLightObject.enabled = true;
			}
			else
			{
				FlashLightObject.enabled = false;
			}
		}
		//power management 

		if (FlashLightObject.enabled == true)
		{
			Batterypower -= 1.0f;
		}
		
		// no power     
		if (Batterypower <= 0)
		{
			FlashLightObject.enabled = false;
			Batterypower = 0;
		}   
	}
}

thank you