Hello guys, i got a runner game and my player dies when it collides with an obstacle.I made a slow motion after the collision to make the game cooler. On the game over screen i got restart button and after i press it game starts again but the time is still slow. I couldn’t solve the issue please help me.
There is my slow-motion code
using UnityEngine;
public class TimeManager : MonoBehaviour
{
public float slowdownFactor = 0.05f;
public float slowdownLength = 4f;
private void Update()
{
Time.timeScale += (1f / slowdownLength) * Time.unscaledDeltaTime;
Time.timeScale = Mathf.Clamp(Time.timeScale, 0f, 1f);
}
public void DoSlowMotion()
{
Time.timeScale = slowdownFactor;
Time.fixedDeltaTime = Time.timeScale * .02f;
}
}
and there is my Restart code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Restart : MonoBehaviour
{
public void RestartGame()
{
SceneManager.LoadScene("Level01");
}
}
and finally the collision code
void OnCollisionEnter (Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
movement.enabled = false;
audioSource.pitch = speed;
timeManager.DoSlowMotion();
FindObjectOfType<GameManager>().gameOver();
FindObjectOfType<GameManager>().EndGame();
CountTime();
}
}