Problem in script Flashlight Energy Bar

where is problem? 21,41 BCE0005 Unknown identifier: Flashlight
22,37 BCE0005 Unknown identifier: energybar

#pragma strict
    var lightSource : Light; //Connect the light source in the Inspector
    static var energy : float = 100; //The energy amount of the flashlight
    static var turnedOn : boolean = false; //Boolean to check whether it's turned on or off
    private var drainSpeed : float = 2.0; //The speed that the energy is drained
     
    function Update () {
    if (Input.GetKeyDown(KeyCode.F)) ToggleFlashlight();
    }
     
    //When the player press F we toggle the flashlight on and off
    function ToggleFlashlight () {
    turnedOn=!turnedOn;
    if (turnedOn  energy>0) {
    TurnOnAndDrainEnergy();
    } else {
    lightSource.enabled = false;
    }
    }
        function OnGUI () {
    GUI.BeginGroup( Rect(40, 10, 218 * (Flashlight.energy/10.0) +35 , 100) );
    GUI.Label( Rect(0, 0, 272, 90), energybar );
    GUI.EndGroup();
    } 
    //When the flashlight is turned on we enter a while loop which drains the energy
    function TurnOnAndDrainEnergy () {
    lightSource.enabled = true;
    while (turnedOn  energy>0) {
    energy -= drainSpeed*Time.deltaTime;
    yield;
    }
    lightSource.enabled = false;
    }
     
    //This is called from outside the script to alter the amount of energy
    static function AlterEnergy (amount : int) {
    energy = Mathf.Clamp(energy+amount, 0, 100);
    }

You have never defined energy bar or flashlight is.

if energy bar and flashlight are sprites u need to load the sprites in the script

Yes. Near the top of your script (outside any functions) put:

public var Flashlight:Sprite;

Now look at the script in the inspector. You’ll see a “slot” for a sprite. Drag your flashlight object into that slot.

No, wait. I misunderstood what you were doing. Flashlight isn’t a Sprite; it’s your script. “energy” is a variable in your script. You don’t need a “Flashlight.” reference to it at all.

energybar, you want that to be a Texture2D. Same as the code I posted first, except with Texture2D instead of Sprite.

    GUI.BeginGroup( Rect(40, 10, 218 * (energy/10.0) +35 , 100) );

I put it there … but now I shows
24,37 BCE0005 Unknown identifier: energybar

#pragma strict
    var lightSource : Light; //Connect the light source in the Inspector
    static var energy : float = 100; //The energy amount of the flashlight
    static var turnedOn : boolean = false; //Boolean to check whether it's turned on or off
    private var drainSpeed : float = 2.0; //The speed that the energy is drained
     
    function Update () {
    if (Input.GetKeyDown(KeyCode.F)) ToggleFlashlight();
    }
     
    //When the player press F we toggle the flashlight on and off
    function ToggleFlashlight () {
    turnedOn=!turnedOn;
    if (turnedOn  energy>0) {
    TurnOnAndDrainEnergy();
    } else {
    lightSource.enabled = false;
    }
    }
        function OnGUI () {

    GUI.BeginGroup( Rect(40, 10, 218 * (energy/10.0) +35 , 100) );

    GUI.Label( Rect(0, 0, 272, 90), energybar );

    GUI.EndGroup();

    } 
    //When the flashlight is turned on we enter a while loop which drains the energy
    function TurnOnAndDrainEnergy () {
    lightSource.enabled = true;
    while (turnedOn  energy>0) {
    energy -= drainSpeed*Time.deltaTime;
    yield;
    }
    lightSource.enabled = false;
    }
     
    //This is called from outside the script to alter the amount of energy
    static function AlterEnergy (amount : int) {
    energy = Mathf.Clamp(energy+amount, 0, 100);
    }

where is the problem?

This. You still haven’t defined energybar.