Missing Component Error

Hello Community :smiley:
Im pretty new to Unity and I want to learn as much as possible. But since I added the Script for a flashlight that should turn on and off I always get this error message:

MissingComponentException: There is no ‘Light’ attached to the “flashlight” game object, but a script is trying to access it.
You probably need to add a Light to the game object “flashlight”. Or your script needs to check if the component is attached before using it.
flashLight.Update () (at Assets/Scripts/flashLight.js:11)

And i get it around 50 times per second. It is realyl annoying… :frowning: But the strange thing is, that the script is bound to the flashlight but in the script nothing asks for it (As far as i know).

Here is the Script:

#pragma strict

var on : boolean = true;

on = true;

function Update()

{

if(Input.GetKeyDown(KeyCode.F))

    on = !on;

if(on)

    light.enabled = true;

if(!on)

    light.enabled = false;

}

And my Objects are ordered like this:

Player (First Person Comtroller)

   Graphics

   Main camera

           flashlight

                 default (it marks the flashlight when i select it)

                 light

I relly hope you can help me… :slight_smile:
This Error is driving me nuts since 3 Days
Thanks :smiley:

-Simple_Zomb
Other Information:
Im using Unity 4.3 Free on a Mac (OSX 10.9.3)

‘light’ is a shortcut for the light component. It is equivalent to:

gameObject.GetComponent(Light)

So you code will throw the error if this script is on the same game object as the Light component. If they are on the same object, look for a second copy of the script on another game object.