Slow down time multiple hits mess (Solved)

Hello,

im new to unity but already finishing my first game, very small basic project im doing for android OS, well i have a problem wen using the slow down time in player collision:

IEnumerator OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == “Obstacle”)
{
Time.timeScale = 1f / slowDown;
Time.fixedDeltaTime = Time.fixedDeltaTime / slowDown;
yield return new WaitForSeconds (0.1f);
Time.timeScale = 1f;
Time.fixedDeltaTime = Time.fixedDeltaTime * slowDown;
//FindObjectOfType().EndGame();
}

This works perfectly wen player colides with one objects but, if i hit another object wen this script is being performed unity will execute it again and it becames a mess.
I just wanted to turn it off while it is acting with the first object it collided, i tryed with a bool variable but could not make it work, any ide on how to achieve this?

Thanks!

Could you provide the example you tried with a boolean? I dont see how it wouldnt work with one?

1 Like

I ended up solving it with a boolean :slight_smile:

But thanks Rob!