Time passed

hey guys i trying to think of the right way(or a way rather) to excutes certain pieces of code based on time passed.

basically how would i code:

Worded example

if (John hasnt been hit for 5 seconds)

{
    //excute something
}

also another one im having trouble with is i wont point to be added is two object collide

this is actual code im using at the moment

if(Hit.gameObject.name == "Ball" | Hit.gameObject.name == "JakeL")
        {
            Score -= 100;
         }

now the problem with this is, It works, but if the ball bounces off jake and say hit the the wall ,the object that give points, then point have just been taken away then added back that fast ive put distance between object for now but it looks weird lol

is it a way to remedy this? is it possible to add to the code to something like : if the ball and jake collide and doesnt hit the wall then minus points?

any insight is appreciated thanks

Supposing you keep track of the last hit time:

float lastHitTime;

void ExampleHitFunction() {
    lastHitTime = Time.time;
}

You could compare the current timestamp against that:

void Update() {
    float timeSinceHit = Time.time - lastHitTime;
    if (timeSinceHit >= 5f) {
        score -= 100;
    }
}

ok ok i see i need to hit the reference and get more acquainted with time functions thanks for the help and direction