- Home /
OnTriggerStay2D calculate Stay Time before calling other method
Hello
I am using OnTriggerStay2D when a Ball enters a Collision Area. All i want to do is PASS to the next level if the Ball stays in the Collision Area for more than X seconds. Currently when the ball enters the Collision Area and executes OnTriggerStay2D it passes to the next level on the spot. I need it to check if the ball is in the collision area for X seconds and i am fine to pass to the next level. If the ball exists the collision area before the X seconds, it wont pass to the next level.
Thank you:)
Answer by tanoshimi · Jun 07, 2014 at 07:42 PM
Create a counter variable and in every
OnTriggerStay()
add Time.deltaTime to it.Then, in
Update()
, check if the counter exceeds X seconds and, if so, load the next level.If
OnTriggerExit()
is called, reset the counter to 0.
Your answer
![](https://koobas.hobune.stream/wayback/20220613151027im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Move Object by dragging (mobile) makes the balls fall from the cup 1 Answer
How to create sprites in unity at runtime ? 0 Answers
2d rotation and translation issue 1 Answer
Can i change a ball with Rigidbody2D with CircleCollider2D to liquid on collision 0 Answers
End game after livesLeft = 0 0 Answers