I am making a system, where money gets collected and a cash particle flies to the money UI header, which then should increase. How would I detect that a particle has travelled to header or that it got destroyed? Solutions I tried but didn’t work:
Check remainingLifetime of particle (Due to different framerates, remainingLifetime never reaches 0 and the particle gets destroyed before that happens. Using some min threshold almost worked, but during lag I still missed some destroyed particles)
Check particle distance to target (Same issue, particle gets destroyed too soon before I can compare distance)
Compare last frame GetParticles() with current frame GetParticles(). (Somehow got the same result as with number 2)
I have spent way too much time on this and still haven’t figured out how to do this. Any help would be appreciated.
Usually one doesn’t bother to “detect” this… one tells a tweener (such as ITween or Leantween or DOtween) that you want the coin to fly up there and get destroyed when it arrives.
I used tweens before, but sometimes I needed to tween up to 300 objects and that was very bad for performance on mobile. When I changed to particle system, performance improved significantly but sadly sometimes the cash does not update properly.
You don’t want to be using the particles themselves as the source of truth for your money counter. You’re spawning the particles yourself using Emit, I’m assuming? When you spawn the particles, make an estimate for the delay and update the counter based on the delay, not on the graphics. It will always be unreliable (framerate dependent) otherwise.