I did some digging around and I found out that when I set Time.timeScale equal to zero, it will stop only framerate independent stuff and that everything that is in the Update function will still run. Is there a way to pause the whole game? Should I disable the controls by setting the player scripts to Player_scr.SetActive(false)? Or is there a simpler, better way?
public class GUI_scr : MonoBehaviour {
public bool cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10;
public bool[] cbxArr;
public string player1, player2, player3, player4, player5, player6, player7, player8, player9, player10;
public string[] playersArr;
public string score1, score2, score3, score4, score5, score6, score7, score8, score9, score10;
public string[] scoreArr;
void Start()
{
cbxArr = new bool[]{cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10};
scoreArr = new string[]{score1, score2, score3, score4, score5, score6, score7, score8, score9, score10};
playersArr = new string[]{player1, player2, player3, player4, player5, player6, player7, player8, player9, player10};
for(int i = 0; i<cbxArr.Length; i++)
{cbxArr *= true;}*
-
for(int i = 0; i<scoreArr.Length; i++)*
_ {scoreArr = “0”;}_
* }*
* void OnGUI () {*
* DrawGUI ();*
* }*
* public void DrawGUI()*
* {*
* GUI.BeginGroup (new Rect(0,0,100,768));*
* for(int i = 0; i<10; i++)*
* {*
_ GUI.BeginGroup(new Rect(0,60i, 100,80));
GUI.Box (new Rect(0,0,100,25), playersArr);
GUI.Box (new Rect(0,25,70,25), scoreArr.ToString ());_
cbxArr _= (GUI.Toggle (new Rect(80,30,300,30),cbxArr,“”));
GUI.EndGroup ();
}
GUI.EndGroup ();*_
* GUI.BeginGroup (new Rect((Screen.width-90),0,90,768));*
* if(GUI.Button (new Rect(0,0,30, 20), “II”))*
* {*
* PauseGame ();*
* // music OFF*
* }*
* if(GUI.Button (new Rect(30,0,30,20),“o”))*
* {*
* ResetGame ();*
* }*
* if(GUI.Button (new Rect(60,0,30,20),“x”))*
* {*
* QuitGame ();*
* }*
* GUI.EndGroup ();*
* }*
* void PauseGame()*
* {*
* float timeScale = (Time.timeScale != 0 ? Time.timeScale = 0 : Time.timeScale = 1);*
* }*
* void ResetGame()*
* {*
* Application.LoadLevel (0);*
* }*
* void QuitGame()*
* {*
* Application.Quit ();*
* }*
}
------------- my player script ---------------
public class Player_scr : MonoBehaviour {
* public int score;*
* public float movementSpeed;*
* private const string idleAnimation = “idle-06”;*
* private const string walkAnimation = “walk-01”;*
* private const string attackAnimation = “attack-06”;*
* DmgCube_scr dmgCube_scr;
GUI_scr gui_scr;*
* public string moveHorizontal_plug;
public string moveVertical_plug;
public string fire_plug;*
* protected virtual void Start () {*
* score = 0;*
* movementSpeed = 3f;*
* animation[idleAnimation].layer = 1;*
* animation[walkAnimation].layer = 1;*
* animation[attackAnimation].layer = 2;*
* gui_scr = GameObject.Find (“GUI”).GetComponent<GUI_scr>();
dmgCube_scr = transform.FindChild(“dmgCube”).GetComponent<DmgCube_scr>();
_ }*_
* protected virtual void Update () {*
* ControllPlayer();*
* }*
* public void ControllPlayer()*
* {*
* float moveHorizontal = Input.GetAxisRaw (moveHorizontal_plug);
float moveVertical = Input.GetAxisRaw (moveVertical_plug);*
* Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);*
* if(movement != Vector3.zero)*
* {*
* animation.CrossFade (walkAnimation);*
* }*
* else if(!Input.GetButton (fire_plug))
_ {
animation.CrossFade (idleAnimation);
}*_
* if(moveHorizontal != 0 || moveVertical != 0)*
* {*
* transform.rotation = Quaternion.LookRotation(movement);*
* }*
_ transform.Translate (movement.normalized * movementSpeed * Time.deltaTime, Space.World);_
* if(Input.GetButtonDown (fire_plug))
_ {
animation.Blend (attackAnimation);
// play swing sound*_
* dmgCube_scr.Attack();*
* Debug.Log (“gui_scr.scoreArr” + gui_scr.scoreArr[3]);*
* // update players gui - score + 20gc;*
* }*
* } *
* public void AdjustScore(int adj)*
* {*
* score += adj;*
* for(int i = 0; i<gui_scr.scoreArr.Length; i++)
_ {
if(gameObject.name == “mage” + (i+1).ToString ())
{
Debug.Log (“gameObjectName” + gameObject.name);_
gui_scr.scoreArr = score.ToString ();
Debug.Log ("scoreWindow5 = " + gui_scr.scoreArr);
// gui_scr.score1 = score.ToString ();
_ }
}
}
}*_