I’m currently developing an Autorunner that involves changing the game speed with a 0.04f increase to timescale every milestone reached. How do I pause and restore the original values without setting it back to 1?
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
if (MobileInput.Instance.Tap && !isGameStarted)
{
isGameStarted = true;
motor.StartRunning();
Time.timeScale = 1f;
flash.SetActive(false);
}
if(isGameStarted)
{
// Bump the Score Up
score += (Time.deltaTime * modifierScore);
if (lastScore != (int)score)
{
lastScore = (int)score;
scoreText.text = score.ToString("0");
}
}
{
if (isDead)
return;
if (score >= scoreToNextLevel)
LevelUp();
score += Time.deltaTime * difficultyLevel;
scoreText.text = ((int)score).ToString();
}
void LevelUp()
{
if (difficultyLevel == maxDifficultyLevel)
return;
scoreToNextLevel *= 2;
difficultyLevel++;
modifierScore += 1;
Time.timeScale += 0.04f;
}
void Resume()
{
Time.timeScale = 1f;
GameIsPaused = false;
}
void Pause()
{
Time.timeScale = 0f;
GameIsPaused = true;
}
}