Question by
MisterElmir · Feb 23, 2021 at 09:17 PM ·
timescale
why doesnt timeScale get back to 1f
ok so i have a script in which my timeScale = 1f; doesnt work basically when you collect all the stars in the level it gives you a victory screen, and there is a restart button when you click it everything is still frozen, however the RestartLevel() does contain both the SceneManagement and Time.timeScale = 1f; how do i fix this?
Comment
using UnityEngine; using UnityEngine.SceneManagement;
public class Victory : MonoBehaviour { private Star[] _stars;
public static bool Win;
public GameObject winPanel;
private void OnEnable()
{
_stars = FindObjectsOfType<Star>();
}
void Update()
{
foreach(Star star in _stars)
{
if (star != null)
return;
}
Win = true;
winPanel.SetActive(true);
Time.timeScale = 0f;
}
public void NextLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
Time.timeScale = 1f;
}
public void MainMenu()
{
SceneManager.LoadScene("MainMenu");
Time.timeScale = 1f;
}
public void RestartLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
Time.timeScale = 1f;
}
} this is the script