Toggling a script on/off using the keyboard?

^ This.

i'm making a showroom, and the object i'm showing is rotating due to a script i wrote...now i want to be able to toggle this script on and off by pressing R on the keyboard...this is what i got so far

    if(Input.GetKeyDown("r"))

    {

        GetComponent("NewBehaviourScript").enabled = false;

    }

if(Input.GetKeyDown("t"))

    {

        GetComponent("NewBehaviourScript").enabled = true;

    }

}

disabling works just fine, re#enabling does not.

any help?

thanks in advance

h4wkeye

If the script is disabled, then Update (which presumably is where this code is) isn't running, so naturally it can't reenable itself. You'd want to enable/disable it from another script. (As an aside, better to not use strings with GetComponent...slower and not type-safe.)

Alright guys, thanks to Eric5h5 it's working now. i'll share my script here in case someone else needs it.

Enable.js

function Update () {

    if(Input.GetKeyDown("r"))

    {

        GetComponent("NewBehaviourScript").enabled = !GetComponent("NewBehaviourScript").enabled;

    }}