I need a shooting hit effect to happen some time after you shot the target via Raycasting, to imitate a time it takes for a bullet to hit a target. (Works okay for slow targets, fast bullets, and short distances, I think. Just saying in case you want to say me I shoudn’t use that approach).
Anyway, I was applying different effects via different coroutines, like one for harming, one for SFX, one for sounds. But I figured out that creating multiple coroutines instead of just one, considering I just need the same delay for everything, is a waste of resources (as far as I know each coroutine is creating a timer and watch it every frame, and make a bit of garbadge, for some reason, idk well how it works but I got the idea), so yeah, why don’t pack all in one coroutine.
So, in the end I got something like this abomination here:
StartCoroutine(MakeHit(effectManager.getDelay(cachedHits[k].point), bonuspart, DistanceReducedInt(damage, cachedHits[k].distance), DistanceReducedInt(impulse, cachedHits[k].distance), cachedHits[k], forwardVector, type, effectManager.PrepareSoundSource(cachedHits[k].point, currentshootable.HitLoudness)));
Yeah… Any advices how to achieve this a better way?
To give some context, for something like late game OP rifle, it can penetrate up to 5 targets every 0.08 seconds, making up to 62.5 corotunes per second, which is considerable.