Enable and Disable a script

What I’m trying to do is just enable and disable a script with a keypress. I know it’s probably very simple, but I’m not very familiar with references to other scripts within a script. What I would like to have is something like this:

function Update () {

if (Input.GetKeyDown(“l”)) {

if (renderer.enabled == true)
    renderer.enabled =  false;
    else

    renderer.enabled = true;
    }

}

but of course instead of enabling and disabling a renderer, enabling and disabling a script.

Use GetComponent; you could do the same thing with the renderer since “renderer” is a shortcut for “GetComponent(Renderer)”. By the way you could simplify that code (and replace the string with an enum) as:

function Update () {
    if (Input.GetKeyDown(KeyCode.I)) {
        renderer.enabled = !renderer.enabled;
    }
}