Hi guys, I made a pause script. In that script I want to have my prefab (which is just a transparent png image/sprite saying pause) appear when the esc button is pressed and disappear when the escape button is pressed again.
I have everything else working to stop the game. The prefab does appear when I press pause… but it seems when I try to unpause, the prefab still remains. And when I pause again it just overlays the previous prefab.
I am still learning this whole thing, so I apologize in advance if it’s something simple. Any advice on how to fix this or a better way to implement is appreciated. Thanks
PauseScript
using UnityEngine;
using System.Collections;
public class PauseScript : MonoBehaviour {
public bool CanPause;
void Start () {
CanPause = true;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {
GameObject newPause = (GameObject)Instantiate(Resources.Load("Pause"));
if(CanPause)
{
Debug.Log("pause");
Time.timeScale=0;
//GameObject Pause = (GameObject)Instantiate(Resources.Load("Pause"));
audio.pitch = Time.timeScale = 0;
CanPause = false;
}
else
{
Time.timeScale=1;
GameObject.Destroy(newPause);
audio.pitch = Time.timeScale = 1;
CanPause=true;
}
}
}
}