Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PaxForce · Oct 24, 2014 at 04:13 PM · timepausetimescale

Can't really pause my game

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[i] = true;}
         
         for(int i = 0; i<scoreArr.Length; i++)
         {scoreArr[i] = "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,60*i, 100,80));
             GUI.Box (new Rect(0,0,100,25), playersArr[i]);
             GUI.Box (new Rect(0,25,70,25), scoreArr[i].ToString ());
             cbxArr[i] = (GUI.Toggle (new Rect(80,30,300,30),cbxArr[i],""));
             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[i] = score.ToString ();
                 Debug.Log ("scoreWindow5 = " + gui_scr.scoreArr[i]);
                 // gui_scr.score1 = score.ToString ();
             }
         }
     }
 }








Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by PaxForce · Oct 25, 2014 at 06:17 AM

I've come up with a simple solution, which works. I don't know if this is the best way to resolve this problem, but since nobody else answered my question and I'm in kind of a hurry, I'll accept my own answer. I added a boolean gameControls to my ControllPlayer function.

 public void ControllPlayer()
     {
         if(gameControls)
         {
             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;
             }
         }
     }    
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pause game that not using deltatime for movment 1 Answer

time.unscaled time help please? 1 Answer

Pause button 2 Answers

Pausing an Invoke for a time 2 Answers

Pause menu doesn't pause everything 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges