Slow Motion Issues!

Hi Guys,

I am currently having issues with trying to “temporarily” slow down time after the player is hit. I have read around the forums and answers and can’t figure out why my code isn’t working.

//These Methods are in the same Class..

public void TakeDamage(int atkdmg, int animeControllerNum) {
hurtIdentifier = animeControllerNum;
currentHealth -= atkdmg;
healthSlider.value = currentHealth;
_tookDamage = true;
timeScaleTimer = scaleTimerVal; // (scaleTimerVal set to 2f) to set the timer to control when the game should go back to regular 1f time scale
_turnSlowMoOn = true; 
}

void Update() {
timeScaleTimer -= Time.deltaTime; 

if (timeScaleTimer <= 0) {

timeScaleTimer = 0;
_turnSlowMoOn = false;
}

if (_turnSlowMoOn) {
   if (Time.timeScale == 1f) {
	Time.timeScale = .5f;
	}
 else {Time.timeScale = 1f;
	Time.fixedDeltaTime = .02f * Time.timeScale;
			}
		}

Hey, it looks like the time scale will be flipping between 1 and 0.5 each frame when _turnSlowMoOn is true. Can you try changing it to something like:

if (_turnSlowMoOn) {
    Time.timeScale = 0.5f;
}
else {
    Time.timeScale = 1.0f;
}
Time.fixedDeltaTime = 0.02f * Time.timeScale;