'enabled' is not a member of UnityEngine.Component

I was working on a project before, saved it, and when I went to compile it I got this error. The line it is having a problem with is:

script.enabled = false;

Every other time I ran it before, I never got this error. Nothing has changed from 2 days ago to now.

The full code this line is in is (it’s a menu named “Dead,” a menu shown for player death):

var newSkin : GUISkin;
var logoTexture : Texture2D;
function theFirstMenu() {
    //layout start
    GUI.BeginGroup(Rect(Screen.width / 2 - 150, 50, 300, 200));
    //the menu background box
    GUI.Box(Rect(0, 0, 300, 200), "You died in the pit. You were *just* there.");
    //logo picture
    GUI.Label(Rect(15, 10, 300, 68), logoTexture);
    ///////main menu buttons
    //game start button
    if(GUI.Button(Rect(55, 50, 180, 40), "Start Over")) 
       	var script = GetComponent("Dead");
    	script.enabled = false;
    //quit button
    if(GUI.Button(Rect(55, 150, 180, 40), "Main Menu")) 
    //layout end

function OnGUI () {
    //load GUI skin
    GUI.skin = newSkin;
    //execute theFirstMenu function

Hoping to resolve this error with the line. Thanks!

The error you are getting is popping up probably because you’ve added #pragma strict somewhere at the top, which enforces certain checks to happen.

According to the Unity documentation, GetComponent returns a Component type. If a string is used as the parameter, there is no hard script type to deduce the return type from, so it just returns a Component.

By looking at the list of members that Component has, you can see that there is no enabled member. If you are familiar with the concept of inheritance and polymorphism, you’ll know that your Dead script has an enabled member because that member is inherited from Behaviour. But since you are receiving the dead script as a Component instead of a Dead type, which is earlier along the heirarchy, you cannot access it’s enabled member while it’s perceived as a Component.

You should explicitly state that var script is of type Dead by using the actual type instead of a string. This will make sure it returns a Dead type, like so:

var script = GetComponent(Dead);

Don’t use quotes in GetComponent, that makes it return Component (which does not have an enabled property as you can see in the docs) instead of your script type.