Timer stop

I’m trying to make a script to destroy a door over time but only when a character is touching it and i want the timer to stop then start from where it left off here is my script so far
var seconds = 60;
var Firstcasulty = 50;
var Secondcasulty = 35;
var Thirdcasulty = 20;
var Door : GameObject;
var Door1 : GameObject;
var Door2 : GameObject;
var Door3 : GameObject;

function Start () {

}

function Countdown () {
if (–seconds == 0)
Destroy(Door);

if(seconds == Firstcasulty)
Destroy(Door1);
if(seconds == Secondcasulty)
Destroy(Door2);
if(seconds == Thirdcasulty)
Destroy(Door3);

}

function OnTriggerEnter(Other : Collider)
{
if(Other.CompareTag(“Player”))
InvokeRepeating (“Countdown”, 1.0, 1.0);
}
function OnTriggerExit(Other : Collider)
{
if(Other.CompareTag(“Player”))
}
I kind of want it like the barricades in Nazi zombies
Thanks :smile:

As far as I can tell all you’re missing is the call to stop the invoke when the player moves away. Try:

function OnTriggerExit(Other : Collider)
{
  if(Other.CompareTag("Player"))
    CancelInvoke("Countdown");
}

Actually it’s probably a bit more complex that that. I think you need to keep track of the number of contacts you have (there could be more than one).

var numContacts : int;

function OnTriggerEnter(Other : Collider)
{
	if(Other.CompareTag("Player"))
	{
		if (numContacts++ == 0)
			InvokeRepeating ("Countdown", 1.0, 1.0);
	}
}

function OnTriggerExit(Other : Collider)
{
	if(Other.CompareTag("Player"))
	{
		if (--numContacts == 0)
			CancelInvoke("Countdown");
	}
}

Thanks man that really helped :smile: