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 ();
			}
}

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 ();
         }
}

Thanks it Works perfect!