title: How to make a mute and unmute button in swift?
body: <p>I am trying to make a mute and unmute in sprite kit swift. I'm able to mute the background music, but I can't unmute it. Here is some code for reference:</p>
  
  <pre><code>var backgroundMusicPlayer = AVAudioPlayer()
  var speaker = SKSpriteNode(imageNamed: "speaker")
  var nospeaker = SKSpriteNode (imageNamed: "nospeaker")
  
      override func touchesBegan(touches: Set&lt;NSObject&gt;, withEvent event: UIEvent)
  
      for touch in (touches as! Set&lt;UITouch&gt;) {
          let location = touch.locationInNode(self)
          if self.nodeAtPoint(location) == self.speaker{
              backgroundMusicPlayer.pause()
              self.nospeaker.anchorPoint = CGPointMake(0, 0.5)
              self.nospeaker.position = CGPointMake(CGRectGetMinX(self.frame) + self.speaker.size.width / 3, CGRectGetMaxY(self.frame) - self.speaker.size.height * 4)
              self.addChild(nospeaker)
          }
          if self.nodeAtPoint(location) == self.nospeaker{
              backgroundMusicPlayer.play()
          }
      }
  }
  </code></pre>
  
  <p>If someone can help me with how to make this happen, that would be greatly appreciated. In a way I want to touch in the speaker location to replace the speaker node with nospeaker nodeand then pause the AVAudioPlayer. If I touch in that location again, I needs to revert to the speaker node and play the AVAudioPlayer.</p>