Console error says its not a member of component, when it is.

Hi, I have this piece of code:

var enemyScript = hit.transform.GetComponent(scriptEnemy);

    if(hit.transform.tag == tagName){
        
        //var position = Vector3(Random.Range(-9,9),Random.Range(-4,4), 0);
        //hit.transform.position = position;
        enemyScript.numberOfClicks -= 1;    //reduce the number each click
        //check that the object is at 0 before adding the points to the score
        if (enemyScript.numberOfClicks == 0)
            score += enemyScript.enemyPoint;    //add point to our overall score
        
    } 
    
    if (hit.transform.tag == tagName2){
    
        //var position = Vector3(Random.Range(-9,9),Random.Range(-4,4), 0);
        //hit.transform.position = position;
        enemyScript.numberOfClicks -= 1;    //reduce the number each click
        //check that the object is at 0 before adding the points to the score
        if (enemyScript.numberOfClicks == 0)
            score += enemyScript.enemyPoint;    //add point to our overall score
            Flash();
    } 

When run, the console says "‘numberOfClicks’ is not a member of ‘UnityEngine.Component’. " When it is declared as follows in scriptEnemy out with any functions:

var numberOfClicks  : int           = 2;    //how many times to click on an object before it gets destroyed 

Anyone know whats happening here?

Thanks,

Jack

The error is correct–numberOfClicks is, indeed, not a member of Component at all. It’s a member of your script. Your script is a Component, but a Component is not your script; that’s known as inheritance. I assume you’re not using Unity 3.4, because otherwise “var enemyScript = hit.transform.GetComponent(scriptEnemy);” would type enemyScript correctly as scriptEnemy rather than Component. If you’re not using Unity 3.4, then you have to cast manually, such as “var enemyScript = hit.transform.GetComponent(scriptEnemy) as scriptEnemy” so you don’t end up with Component as the type.