Problem with tag??

I have code attached to a first person camera and a compiler error keeps appearing "unknown identifier" - enemy

var bulletDamage = 50;
var range = 5000;
var hit :  RaycastHit;

Screen.showCursor = false;

function Update()
{
    if(Input.GetButtonDown("Fire1"))
    {
        if(Physics.Raycast(transform.position, transform.forward, hit, range))
        {           
            if(hit.collider.gameObject.tag == "enemy")
            {
                //print("HIT");
                enemy.BroadcastMessage("OnHit");

            }
        }
    }
}

The next bit is attached to the enemy prefab which is spawned on the screen when the player gets within a certain range.

static var AIHEALTH = 100;

function Awake()
{
    gameObject.tag = "enemy";
}

function OnHit() 
{
     if(AIHEALTH <= 0)   
     {
        KillObject();
     }
     else
     {
        AIHEALTH -=50;
     }
}

function KillObject()
{
    Destroy(gameObject);
}

any help would be great, thanks.

It needs to be:

hit.collider.BroadcastMessage("OnHit");

as you never declared the enemy variable

it's this bit here

  if(hit.collider.gameObject.tag == "enemy")
            {
                //print("HIT");
                enemy.BroadcastMessage("OnHit");

            }

what you want is either a component or game object in there. declare your enemy as a variable in the top of your script and put in function Update.

var Enemy : GameObject;

function Update()
{
    if (Enemy == null)
    {
       Enemy = GameObject.FindWithTag("enemy");
    }
}

instead of setting you enemy's tag when awake set it on the prefab in the inspector, that way you wont have a problem.