- Home /
Keep doing something while colliding
Hi, first of all sorry for my bad english. I'm working on a spaceships game and there's a kind of star's path and if the spaceship moves over it the life should decrease per every 0.5 seconds, but if I use the function OnTriggerEnter2D() the life decrease only once even if the ship keeps over the path. How can I do what i need? Thanks for reading and for your help!
Answer by $$anonymous$$ · Oct 11, 2014 at 07:26 AM
You can use OnTriggerStay2D() --> TRIGGER
OnTriggerStay can be costly in terms of performance, necessary sometimes but you could use either a coroutine or invoke repeating(with your time of 0.5) method ins$$anonymous$$d which would trigger using OnTriggerEnter2D() and end on OnTriggerExit2D(). A far less power hungry way of doing it as the invoke will only run twice per second. OnTriggerStay will run every frame, maybe 60 times a second.
Your answer
Follow this Question
Related Questions
OnTriggerEnter with exact spot of collision 2 Answers
Colliding two GameObjects 1 Answer
Collision problem in C# 4 Answers
2 objects collide, need to destroy one 2 Answers
Destroying an object on collide depending on the impulse magnitude. 0 Answers