So… I have this problem. It might be even a little funny, but I almost lost all hope for solving it so I’m kindly begging you for help.
This is my pauseScript.cs which is working… in a mysterious way.
First - If the game is on and player will die I’m triggering GameOver function from this script. Game pauses, pausePanel is showing up and I can restart game or go to the main menu. Working like a charm.
The problem is when I want pause game. First of all is remembering my clicks as it happened during the gameplay, so after resuming game my hero will jump like crazy squirrel (which he is not unfortunately cause that way I could have “feature” and not a bug). Second problem is happening after pausing game, resuming and then inevitable GameOver is coming… though it’s not Player is destroyed, sound is being played, vibration is on… but the camera won’t stop, score is still counting and pause menu with gameover text and restart button is not showing up (you need to actually click on it, but even then no restart button is on - only resume one).
Please help me since I’m tweaking this code and it’s probably something obvious but it still sneaking out my grasp.
using UnityEngine;
using System.Collections;
public class pauseScript : MonoBehaviour {
public static pauseScript instance;
public bool paused;
public GameObject gameOverText;
public GameObject playButton;
public GameObject replayButton;
[SerializeField]
private GameObject pausePanel;
void Start () {
paused = false;
replayButton.gameObject.SetActive(false);
}
public void Pause(){
paused = !paused;
if(paused){
Time.timeScale = 0;
pausePanel.SetActive(true);
playButton.gameObject.SetActive(true);
replayButton.gameObject.SetActive(false);
gameOverText.gameObject.SetActive(false);
}
}
public void GameOver(){
paused = !paused;
if(paused){
Time.timeScale = 0;
pausePanel.SetActive(true);
playButton.gameObject.SetActive(false);
replayButton.gameObject.SetActive(true);
gameOverText.gameObject.SetActive(true);
}
}
public void ResumeGame(){
paused = paused;
if (paused){
pausePanel.SetActive(false);
Time.timeScale = 1;
}
}
public void GoToMenu(){
Time.timeScale = 1;
pausePanel.SetActive(false);
Application.LoadLevel("02-MainMenu");
}
public void Restart(){
Time.timeScale = 1;
Application.LoadLevel("05-Game");
}
}