Time.timeScale Question

Hi,

Im using this script below, what it does is when my game starts there is a 2d texture covering the game area and a PlayNow Button. I want the game to be paused as soon as it starts then when the player hits the playnow button the game will be playable and it is un-paused.

var displaySplashBackground : boolean = true;
var splashBackground : Texture2D;

var PopupSkin : GUISkin;

function OnGUI()
{
	GUI.skin = PopupSkin;
	
	if(displaySplashBackground)
	{
		GUI.Label (Rect (0,0, 600,450), splashBackground, GUIStyle.none);
		Time.timeScale = 0; //pause game
				
		if (GUI.Button (Rect (180, 10, 222,76), "","PlayNow"))
   			{
   		 		displaySplashBackground = false;
   		 		Screen.showCursor = false;//hide the cursor on play
				Time.timeScale = 1; //now un-pause the game
   		 	}
	}	
}

This works fine inside of Unity but when I create a web player build it does not seem to be working? So Im not sure if Im doing something wrong? or is there another way to pause the game?

Edit ok it seems to be pausing the player just not the enemies :slight_smile: So at least the player will not run off of the edges which is good and I’ll try not to do any pausing unless all enemies are dead.

Time.timeScale affects physics and Time.deltaTime. The method I would use is to create a GameController object and give it a script that has the variable… isPaused. Then all your enemies, and players and such reference the game controller and ask if it is paused… observe:

// example update:
function Update(){
	if(GameObject.Find("GameController")){
		if(GameObject.Find("GameController").GetComponent("GameController").isPaused) return;
	}
}

// your GameController script

var isPaused=false;

function Update(){
	if(isPaused){
		Time.timeScale=0.0;
	} else {
		Time.timeScale=1.0;
	}
}

Wow Thank you very Much !!!
Im implementing it right now :slight_smile: