how to stop a script for a while?

how to stop a script for a while? I wish that when the player passes a trigger, a script is blocked for a few seconds,but doesn't work

var timeOut = 3.0;

function Awake ()
{
    Invoke ("Enable", timeOut);
}

function OnTriggerEnter (collision : Collider)
{

   if (collision.gameObject.tag == "Player")
   {
   GameObject.Find("messoplayer").GetComponent("input").enabled=false;
   GameObject.Find("Player").GetComponent("FPSWalker").enabled=false;
   GameObject.Find("Player").GetComponent("MouseLook").enabled=false;
   }
} 

function Enable ()
{
   GameObject.Find("messoplayer").GetComponent("input").enabled=true;
   GameObject.Find("Player").GetComponent("FPSWalker").enabled=true;
   GameObject.Find("Player").GetComponent("MouseLook").enabled=true;
   } 

Whenever I see a question involving "do x for t seconds" I always suggest using the MonoBehaviour Coroutine.

Do something like this:

void OnTriggerEnter(Collider other)
{
    if(other.gameObject.name != "Player") return; //skips the rest of the function if something else entered the trigger besides what we want to actually trigger the event
    StartCoroutine(MyCoroutine());
}
IEnumerator MyCoroutine()
{
    //disable the desired script here
    yield return new WaitForSeconds(10F);
    //enable it here
}

That code will start a Coroutine when our Player enters the trigger. The Coroutine will then do something, wait 10 secs and do something else. Should get you the desired result.

Cheers,

==

p.s. I code in C#, obviously. If you need Javascript you could compare my script to the docs on Coroutines to port it over.

One way you could do it would be to either disabable the component by setting enable to false. You might have to do that from another script though as I'm not sure you can get a disabled script to re-enable itself. You can use the getcomponent function to obtain a reference to the necessary script.

You could also try encapsulating the code you want disabled in a big

if(!disabled) {...}

clause. You'd set the disabled flag in the trigger collision code given your example.

Hope that helps.

disable script(WORK):

function OnTriggerEnter (collision : Collider)
{

   if (collision.gameObject.tag == "Player")
   {
   GameObject.Find("messoplayer").GetComponent("input").enabled=false;
   GameObject.Find("Player").GetComponent("FPSWalker").enabled=false;
   GameObject.Find("Player").GetComponent("MouseLook").enabled=false;
   print("HELLO");   }
}   

re-enable script(DOESN'T WORK)

var timeOut = 2.0;
function OnTriggerEnter (collision : Collider)
{
   if (collision.gameObject.tag == "Player")
   {
  print("hello1");  
Invoke ("Activate", timeOut);
}
}   

function Activate ()
{  
GameObject.Find("messoplayer").GetComponent("input").enabled=true;
   GameObject.Find("Player").GetComponent("FPSWalker").enabled=true;
   GameObject.Find("Player").GetComponent("MouseLook").enabled=true;
   print("PROVA3"); 
}