question about my the code i edited

Hi i recently got a pause menu that im tyring to edit for my online game there was a bug where after switching levels it stayed paused so you needed press pause key twice (once to pause in that level and once to un-pause) so i copied the code from the un-pause section and added it after the function load level so it loads and pauses.

Since i have made this minor change the main level lags a lot when loading up is there any way to refine the un pause part of the code so it don’t lag the loading of levels so much.

It is in Java-script

here are some snippets

function Update(){

	//check if pause button (escape key) is pressed
	if(Input.GetKeyDown("escape")){
	
		//check if game is already paused		
		if(pauseEnabled == true){
			//unpause the game
			pauseEnabled = false;
			Time.timeScale = 1;
			AudioListener.volume = 1;
			Screen.showCursor = false;			
		}
		
		//else if game isn't paused, then pause it
		else if(pauseEnabled == false){
			pauseEnabled = true;
			AudioListener.volume = 0;
			Time.timeScale = 0;
			Screen.showCursor = true;
		}
	}
}

load level and unpause under: Funtion OnGUI

Application.LoadLevel(LogOutSceneName);
			
			Time.timeScale = 1;
			AudioListener.volume = 1;
			Screen.showCursor = false;

edit: i realise on my online game i wont need the pause function but for now i need it for testing the performance of switching and creating a options menu
Credit for the menu: http://forum.unity3d.com/threads/96231-New-Pause-Menu

Would probably need to see what’s going on in your OnGUI() to determine what is lagging. If you have an Application.LoadLevel() in OnGUI that could potentially be getting triggered multiple times depending on how you’re triggering it.

it is ment to get triggered when the gui button pressed in the menu