Pause button not working correctly
Hello
I am writing a pause button for my game (Game for mobile phones).
My Pause script:
 using UnityEngine;
 using System.Collections;
 
 public class PauseScript : MonoBehaviour {
 
     public bool paused;
     // Use this for initialization
     void Start () {
         paused = false;
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Space))    
         {    
             paused = !paused;
         }
 
         if (paused)    
         {    
             Time.timeScale = 0;   
         }    
         else if (!paused)    
         {    
             Time.timeScale = 1;
         }
     }
 
     public void Pause()    
     {
         paused = !paused; 
 
         if (paused)
         {    
             Time.timeScale = 0;
         }
         else if (!paused)
         {    
             Time.timeScale = 1;
         }
     }
 }
 
               And Jump that is written like this jump = Input.GetButton("Fire1");
When I touch button my player jumps and the game does not pause.
How I can make my game pause and player doesn't jump?
Hi @nemesises This whole thing is not needed. Only the Update() is necessary. But the functions should come under if
using UnityEngine; using System.Collections;
public class PauseScript : $$anonymous$$onoBehaviour {
  public bool paused;
  // Use this for initialization
  void Start () {
      paused = false;
  }
 
  // Update is called once per frame
  void Update()
  {
      if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))    
      {    
          paused = !paused;
 
      if (paused)    
      {    
          Time.timeScale = 0;   
      }    
      else if (!paused)      
          Time.timeScale = 1;
      }
  }
 
                 I have this from tutorial. And I have Update and Pause in this tutorial.
I have button on Canvas and Button on it. And I have Pause() in OnClick
I just need that my palayer don't jump when I touch the button
Now I am confused with your need. You are using canvasButton to Pause !!! What about the "space" ? What is the need for space bar again?
Answer by Astha_Mishra · Aug 02, 2017 at 10:49 AM
try this
 public class PauseController : MonoBehaviour {
 
  
     bool paused = false ;
     
     // Use this for initialization
     void Start () {
     
         //First set the canvas to false
     }
     
     // Update is called once per frame
     void Update () {
             //every frame this function will be called
             pauseGame ();
     }
 
 
     public void pauseGame()
     {        
         
         if (Input.GetButtonDown ("AnyButton")) {
             paused = true ;
         }
 
         if (paused) {
             canvas.SetActive (true);
             Time.timeScale = 0;
         }
     }
 
     // call this function on button click on the UI button 
     public void Unpause(){
         paused = false;
         if (!paused) {
             canvas.SetActive (false);
             Time.timeScale = 1;
         }
 
     }
     
 }
 
 
              Your answer
 
             Follow this Question
Related Questions
There is a problem with my script... 0 Answers
Move sphere around a cube using conventional physics 1 Answer
Enemy AI: Player attacke when in FOV 0 Answers
How do I make somthing happen when the Player reaches a certain x, y, z position? 0 Answers
How can i look for collisions of the bulidngs in may array ? how can i use OnTRiggerEnter/exit ? 0 Answers