Get script from raycasthit

I have a script called "enemy" in the object that the raycast hits

I use the following script to find all the objects that the raycast hits

   var ray = new Ray (origin, h-origin);
    var hits : RaycastHit[];
    hits = Physics.RaycastAll(ray, 100, enemies);

    for (var  i=0;i<hits.length;i++)
        {
        var hit : RaycastHit = hits*;*
 *hit.transform.enemy.damage(100);*
 *}
*

BCE0019: ‘enemy’ is not a member of ‘UnityEngine.Transform’.


How can I access the enemy script?

The reason you're getting the error is because you need to get the "enemy" component, using GetComponent:

var hit : RaycastHit = hits*;*
*hit.collider.GetComponent(enemy).damage(100);*
*```*
*<p>If you're using Unity iPhone or #pragma strict, you need to cast the component as the appropriate type:</p>*
*```*
*(hit.collider.GetComponent(enemy) as enemy).damage(100);*
*```*
*<p>Also, you might find this syntax more convenient, plus you would need to check if the hit object has an enemy component:</p>*
*```*
*var hits = Physics.RaycastAll(ray, 100, enemies);*
*for (hit in hits)*
 *{*
 *var enemyScript : enemy = hit.collider.GetComponent(enemy);*
 *if (enemyScript) enemyScript.damage(100);*
 *}*
*```*

Well, simply use `SendMessageUp`, like so:

var ray = new Ray (origin, h-origin);
    var hits : RaycastHit[];
    hits = Physics.RaycastAll(ray, 100, enemies);

    for (var  i=0;i<hits.length;i++)
        {
        var hit : RaycastHit = hits*;*
 *hit.collider.SendMessageUpwards("ApplyDamage", 100.0);*
 *}*
*```*
*<p>Hope this helps!</p>*