Unity crashing//Renderer.gameObject.active

I'm having a problem with the following code. when the renderer. active and the .enabled run, unity crashes. I have no clue whats is causeing this to happen. Any help would be greatly appreciated.

static var hasKey = false;

function OnControllerColliderHit (hit:ControllerColliderHit) { if(hit.gameObject.tag== "Key") { //Destroy(hit.gameObject); hasKey = true;


if(hasKey == true && hit.gameObject.tag == "Door")
    renderer.gameObject.active = false;
    renderer.enabled = false;


Renderer could be a component of a GameObject not vice versa.

If you want to enable/disable the renderer use:

renderer.enabled = false;

If you want to activate/deactivate the GameObject use:

gameObject.active = false;

If you deactivate a GameObject, all of its components will also be deactivated/disabled. So you do not have to disable each of the attached components.