Question by
EmissiveSlider · Jan 08 at 10:53 AM ·
scripting problem
Scene Not pausing while canvas popped up
So I was trying to make my Breakout game pause when the player beats the level. It works fine and the panel is there but the only problem is that the game still continues and switches scenes when ball falls to bottom border. I do not know why the code is not working but I did add a time scale function set to 0
Here is my code:
public class Level : MonoBehaviour {
public string menuSceneName = "MainMenu";
public string nextLevel = "Level02";
public int levelToUnlock = 26;
public int nextSceneLoad;
public GameObject winscreen;
public GameObject Ball;
// parameters
[SerializeField] int breakableBlocks; // Serialized for debugging purposes
// cached reference
SceneLoader sceneloader;
public void Continue ()
{
PlayerPrefs.SetInt("levelReached", levelToUnlock);
}
private void Start()
{
sceneloader = FindObjectOfType<SceneLoader>();
nextSceneLoad = SceneManager.GetActiveScene().buildIndex + 1;
}
public void CountBlocks()
{
breakableBlocks++;
}
public void BlockDestroyed()
{
breakableBlocks--;
if (breakableBlocks <= 0)
{
Time.timeScale = 0;
winscreen.gameObject.SetActive(true);
if (nextSceneLoad > PlayerPrefs.GetInt("levelAt"))
{
PlayerPrefs.SetInt("levelAt", nextSceneLoad);
}
}
}
}
Comment