Jump to content
  • Advertisement
Sign in to follow this  
hcted

Help Pausing my Game

This topic is 2547 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I pause my game, the cursor still moves the guys view. Guns, Movement, AI Movement and game time stops, but when I move the mouse when the game is paused, the guys view changes. Heres my code:

//Main Pause Var
@System.NonSerialized
public var paused : boolean = false;
//Private Vars
private var wasLocked = false;
private var chooseQuality : boolean = false;
var weaponHolder : GameObject;

function Start (){
// Find Player
if(weaponHolder == null){
//weaponHolder = gameObject.FindWithTag("Weapon Holder");
}
SetPause(false);
Screen.lockCursor = true;
}

function OnApplicationQuit (){
Time.timeScale = 1;
}

function SetPause (pause : boolean){
Input.ResetInputAxes();
var gos : Object[] = FindObjectsOfType(GameObject);
for (var go : GameObject in gos)
go.SendMessage("DidPause", pause, SendMessageOptions.DontRequireReceiver);

transform.position = Vector3.zero;

if (pause){
if(RayPlayer.onDeath != true){
// Disable Weapons
weaponHolder.SendMessage("pauseWeapon", SendMessageOptions.DontRequireReceiver);
Time.timeScale = 0;
paused = true;
}
}
else{
//Enable Weapons
weaponHolder.SendMessage("unpauseWeapon", SendMessageOptions.DontRequireReceiver);
Time.timeScale = 1;
paused = false;
}
}

function DidPause (pause : boolean){
if (pause){
wasLocked = false;
}
else{
wasLocked = true;
}
}

function Update (){
if(paused){
if (Input.GetKey("escape")){
SetPause(false);
DidPause(false);
}
Screen.lockCursor = false;
}

if(!paused){
if (Input.GetKey("escape")){
SetPause(true);
DidPause(true);
}
Screen.lockCursor = true;
}
//Set Time Scale back For when Dead
if(RayPlayer.onDeath == true){
Time.timeScale = .5;
}
}

function OnGUI (){
if(!wasLocked){
//TimeScale
if(RayPlayer.onDeath != true){
Time.timeScale = 0;
}
if(GUI.Button(Rect(50, Screen.height -240, 60, 20), GUIContent ("Menu" ))){
//
Application.LoadLevel ("MainMenu");
}
if(GUI.Button(Rect(50, Screen.height -210, 60, 20), GUIContent ("Options" ))){
//
QualityOn();
}
if(GUI.Button(Rect(50, Screen.height -180, 60, 20), GUIContent ("Reset" ))){
//
Application.LoadLevel ("NSurvive");
}
if(GUI.Button(Rect(50, Screen.height -150, 60, 20), GUIContent ("Quit" ))){
//
Application.Quit();
}


if(chooseQuality){
//Display Images
GUI.Label(Rect ((Screen.width/2)-250,(Screen.height- 200),100,40), "Quality Settings");

if(GUI.Button (Rect ((Screen.width/2)-150,Screen.height -150,80,20), "High")){
QualitySettings.currentLevel = QualityLevel.Fantastic;
chooseQuality = false;
}
if(GUI.Button (Rect ((Screen.width/2)-250,Screen.height -150,80,20), "Medium")){
QualitySettings.currentLevel = QualityLevel.Good;
chooseQuality = false;
}
if(GUI.Button (Rect ((Screen.width/2)-350,Screen.height -150,80,20), "Low")){
QualitySettings.currentLevel = QualityLevel.Fastest;
chooseQuality = false;
}
}
}
}
function QualityOn (){
chooseQuality = true;
}

Share this post


Link to post
Share on other sites
Advertisement
I see nothing related to handling mouse input and moving the view.
However, I don’t see why you can’t just check if the game is paused and then not update the view if so.


Your pausing mechanism is extremely over-complex. If there was a need at all for an “OnPause” event, it would be for loading a pause menu etc., not for telling each individual object to stop moving.
Pausing should be handled by having 2 timers, one of which keeps track of “virtual” time. When the game is paused, the virtual timers are not updated. Thus, the delta time between updates will be 0, so the time by which you advance objects will be 0, hence they stop moving.

Menus will use the other timer, so they can move and animate while the game is paused.


L. Spiro

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!