Hi all, could anyone explain why this code works with “else if” but doesn’t work if it is only “if”. Thanks.
void Start () {
restart.onClick.AddListener(restart_game);
exit.onClick.AddListener(exit_game);
resume.onClick.AddListener(resume_game);
mainScreen.onClick.AddListener(main_screen);
isGameOver = FindObjectOfType<collision_detect>().is_game_over;
game_paused = false;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Escape))
{
if(game_paused == true)
{
restart_button.SetActive(false);
exit_button.SetActive(false);
gameOver.SetActive(false);
resume_button.SetActive(false);
game_paused = false;
Time.timeScale = 1;
}
else if(game_paused == false)
{
gameOverText.text = "game paused";
restart_button.SetActive(true);
exit_button.SetActive(true);
gameOver.SetActive(true);
resume_button.SetActive(true);
game_paused = true;
Time.timeScale = 0;
}
}