I’m wondering if anyone has some insight on how to start a timer when the player enters a collider (is trigger). I want the player to react as quickly as possible by pressing a button in response to entering the trigger collider. I would also like the system to output a reaction time for each trigger collider. Is this possible?
If i understand correctly what you would like to accomplish I would write something like this:
class colliderWithTimer: MonoHehaviour
private bool isTiming = false;
private float timeTillKeyIsPressed = 0;
void OnCollisionEnter(Collision collision) {
isTiming = true;
}
void Update(){
if (isTiming)
{
timeTillKeyIsPressed += Time.DeltaTime;
}
if (Input.GetKeyDown(KeyCode.S)) // I used S, but ofc this can be something else
{
isTiming = false;
}
}
now the timeTillKeyisPressed can be used to display the time.
Take note!! i do not know if it is the best practice to time in the update function with time.deltatime, but since you catch the keypressed in the update function as well i suspect this wouldn’t give any performance issues. However when your framerate drops very low this can be a problem (but again the keypressed wont be caught either).