half working script help

the first part to my script works but the second part does not. the bit that works is the hide at the start. But when i enter the trigger and press “E” it does not show again. here is my script:

  function Start ( ) 
 {
    var child = transform.GetChild(0);
    child.renderer.enabled = false; 
 }
 function OnTriggerStay(trigger : Collider) {
       if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.E)) {
           var child = transform.GetChild(0);
           child.renderer.enabled = true;
      }
  }

any help or amendments would be great

thanks

What i would recommend is doing it with OnTriggerEnter/OnTriggerExit.

var canHandleKeypress : boolean = false;


function Start ( ) 
  {
     var child = transform.GetChild(0);
     child.renderer.enabled = false; 
  }


function OnTriggerEnter(trigger : Collider) {
        if((trigger.gameObject.tag == "Player") ) {
            canHandleKeypress = true;
       }
   }


function OnTriggerExit(trigger : Collider) {
        if((trigger.gameObject.tag == "Player") ) {
            canHandleKeypress = false;
       }
   }


function Update( )
  {
    if (canHandleKeypress && Input.GetKeyDown(KeyCode.E))
    {
      var child = transform.GetChild(0);
      child.renderer.enabled = true;
    }
  }

I’m not that familiar with javascript, so possible syntax errors here, but you get the general idea.