I've been writing this code quite late so please bear with me. I'm trying to pause the game and show a menu when I'm inside a collider and then when i press a key it should unpause the game and continue but it wont and i cant figure out why.
Here's the very simple (in my eyes) code:
var savedTimeScale : float;
var playerStatus : Player_Status;
var inTheZone : boolean = false;
private var startTime: float = 0.1;
var start:GameObject;
enum Upgrade { None,Main }
private var currentPage:Upgrade;
function Start()
{
currentPage = Upgrade.None;
}
//function for ontriggerenter and pressing button to show menu
function OnTriggerEnter(collider:Collider)
{
playerStatus = collider.GetComponent(Player_Status);
if(playerStatus == null) return;
inTheZone = true;
}
function OnTriggerExit(collider: Collider)
{
playerStatus = collider.GetComponent(Player_Status);
if(playerStatus == null) return;
inTheZone = false;
}
function Pause()
{
savedTimeScale = Time.timeScale;
Time.timeScale = 0;
AudioListener.pause = true;
currentPage = Upgrade.Main;
}
function UnPause()
{
Time.timeScale = savedTimeScale;
AudioListener.pause = false;
currentPage = Upgrade.None;
if(IsBeginning() && start != null)
{
start.SetActive(true);
}
}
function IsGamePaused()
{
return Time.timeScale == 0;
}
function OnGUI()
{
if(inTheZone == true && Input.GetKeyDown(KeyCode.E))
{
Pause();
}
if(Input.GetKeyDown(KeyCode.N))
{
UnPause();
}
if(IsGamePaused() && !IsBeginning())
{
UpgradeMenu();
}
}
function UpgradeMenu()
{
BeginPage(200,200);
GUILayout.Button("Hello");
EndPage();
}
function BeginPage(width, height)
{
//GUI.DrawTexture
GUILayout.BeginArea(Rect((Screen.width-width)/2,(Screen.height-height)/2,width,height));
}
function EndPage()
{
GUILayout.EndArea();
ShowBackButton();
}
function ShowBackButton()
{
if(GUI.Button(Rect(20, Screen.height-50,50,20), "Resume"))
{
UnPause();
}
}
function IsBeginning()
{
return Time.time < startTime;
}
I think it's just a case of a new set of eyes. But by my logic this should work.