Starting a timer with a collision?

OK, this is confusing me, and I"m sure it has some ridiculously simple solution that I’m incapable of seeing right now.

I’d like to start a timer when a character controller hits a certain object. The problem is that if the charactercontroller continues to collide with that object (this variable would be set inside of an OnControllerColliderHit() function), the timer variable continues to set itself to Time.time.

Basic code is:

Function OnControllerColliderHit(hit : ControllerColliderHit) {
if (hit.collider.tag == “Clingable”){
timer = Time.time;
}
}

Obviously my actual code is more complex than that. Currently, what happens is that if a player jumps into a wall that’s tagged the right way, they cling to it, and don’t move, and have restricted movement (can only jump up, or fall down). What I’d like to do is, 3 seconds after attaching to the wall, they automatically fall off, and have to move back towards the wall to cling again. Easiest way to do that with the rest of my code is have a timer that grabs Time.time only the first time a player touches that wall, and then starts again only if they’ve either jumped, or are falling (basically the timer hitting a limit would set a varaible to false).

Man I hope this makes sense, I get a bit rambly…

add some bools… if you attach to a wall, set a variable. then check for the variable, if it’s true… don’t set the value of timer.

Hah, like I figured… ridiculously simple! I’ll try that, thanks!

You could also just check your counter itself. If not 0, then it is running already. Just set it back to 0 when you fall off the wall.