Script crashes Unity

The following script is attached to the player and it crashed Unity.

#pragma strict

var invulTime : float;
 
function Update () {
	invulTime -= Time.deltaTime;
	RespawnInvulnerability();
}

function OnCollisionEnter(Col : Collision){
	invulTime = 1;	
}	

function RespawnInvulnerability(){
	if (invulTime > 0 && invulTime < 1){
		collider.enabled = false;
		print("invul ON");
	}
	if (invulTime <= 0){
		collider.enabled = true;
		print("invul OFF");
	}
}

I’m not that great with coding, so there’s probably a better script to do this with. But what this does is it constantly counts down the invulTime below zero, which means that the collider is enabled. When the player gets hit it sets the invulTime to 1, which means that the collider is disabled in the window between 1 and 0 of invulTime. When the player gets hit it detracts a life from the player and resets the player’s position to the start position of the player. This script then gives the player a second of invulnerability to get going again.

It happens when I’m playing the game in the Unity Game window, the 3 lives are depleted (consequently the player is destroyed) and the Game Over GUI (with a couple of boxes and buttons, Time.timeScale is 0 as well then) is overlayed and hit the play button again to stop playing. The hitting of the play button crashes Unity. Also, hitting the Retry button (Application.LoadLevel(Application.loadedLevel)) in the Game Over GUI crashes Unity as well.

The following error is displayed:
Unity.exe caused an Access Violation (0xc0000005) in module Unity.exe at 001b:012bf610.

Is there something wrong with this script? Perhaps you have an alternative way of doing what I want to do, which possibly won’t crash Unity?

I also tried the following, thinking the constant detracting of Time.deltaTime might be causing it, which didn’t fix the issue.

#pragma strict

var invulTime : float;

function Update () {

	if (invulTime <= 1 && invulTime >= 0){
		invulTime -= 0.01;
	}

	RespawnInvulnerability();
}

function OnCollisionEnter(Col : Collision){
	invulTime = 1;	
}	

function RespawnInvulnerability(){
	if (invulTime > 0 && invulTime < 1){
		collider.enabled = false;
		print("invul ON");
	}
	if (invulTime <= 0){
		collider.enabled = true;
		print("invul OFF");
	}
}

Thanks for your time!

In the comments above, we’ve come to the conclusion that crashes stop if rigidbody.detectCollisions is used instead of collider.enabled. I think collider.enabled is obsolete.

Posting this answer so anyone with a similar problem can find a solution.