OnCollisionStay timing

So basically i have some scenery that when the player hits it it deals damage. but what i want to do is if the player stays on for say 5 seconds it ends in death.

here is what i got:

var Crammus : GameObject;
var crammusScript;
var collisionTime : float = 0;

function Awake () {
	crammusScript = Crammus.GetComponent("CrammusFlying");
	}

function OnCollisionEnter(collision : Collision) {
	crammusScript.SceneryDamage();
}

function OnCollisionStay(collisionInfo : Collision)
	{
		collisionTime = Time.deltaTime;
		if ( collisionTime > 5)
		{
		Application.LoadLevel("Level1");
		}
	}

no the only thing i don’t know how to do is time while there is a collision. I figure my collisionTime = Time.deltaTime; should probably be in an Update function but i can’t put OnCollisionStay as an if, any ideas?

Thanks

You don’t need Update for anything, just change

collisionTime = Time.deltaTime;

to

collisionTime += Time.deltaTime;

If you want the collision time limit to be for 5 seconds per collision, and not 5 seconds total for any and all collisions, then put “collisionTime = 0.0” in OnCollisionEnter to reset it. (Otherwise just leave it the way it is.)

As an aside, if you’re not actually using the collision info for anything, leave it out:

function OnCollisionStay () {

because it’s faster.

–Eric

sweet it worked, thanks

and figures that all i am missing is one “+”