Check if an object is in a trigger for a certain amount of time
How can I check and see if an object is in a trigger for a certain period of time? I want to perform a certain action if the object is in the trigger for around 2 seconds, and not do the action if it is removed before those two seconds. Thanks!
Comment
Best Answer
Answer by vittu1994 · May 16, 2016 at 03:27 PM
Use OnTriggerStay() for the collider and then use a float timer that will decrease by Time.time. Then use OnTriggerExit() when the object leaves the collider and reset the float timer.
Your answer
Follow this Question
Related Questions
Checking when two triggers intersect 1 Answer
Move a object with a trigger? 0 Answers
Pipe Game ... I have to trace water from source to destination 2 Answers
Unity / Oculus - Touch object as trigger 0 Answers
Stop AudioSource on Trigger!!! 1 Answer