- Home /
 
 
               Question by 
               Ryujose · Aug 23, 2014 at 09:53 PM · 
                pausegetkeydowntime.timescaleunpause  
              
 
              Sound on pause it doesn't works.
Hello I want to play a sound on pause but it doesn't work like I want. When I press P it pause but sound is not playing, and when I press R it sound but if it isn't paused and you press R it sounds too.
I want that when you press P and pause play the sound and when you press R unpause and play the sound, and when is unpaused and press R that sound don't play.
Here's my code fragment of my code.
 void update ()
 {
 
 if (Input.GetKeyDown (KeyCode.P))
         {
                     Time.timeScale = 0; 
                     EfectosDeSonido.Instancia.ReproducirSonidoPause ();
                 }
 
 
         if (Input.GetKeyDown (KeyCode.R))
             {
                     Time.timeScale = 1;
                     EfectosDeSonido.Instancia.ReproducirSonidoPause ();
             }
 }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by AngryBurritoCoder · Aug 23, 2014 at 09:58 PM
Change the code at beggining to this...
 bool paused = false;
 
 void update ()
 {
  
 if (Input.GetKeyDown (KeyCode.P) && !paused)
         {
 paused = true;
 EfectosDeSonido.Instancia.ReproducirSonidoPause ();
 Time.timeScale = 0;
          }
  
 if (Input.GetKeyDown (KeyCode.R) && paused)
          {
 Time.timeScale = 1;
 paused = false;
 EfectosDeSonido.Instancia.ReproducirSonidoPause ();
          }
 }
 
              Your answer