title: Unity 5.3 with C# - Toggle Sound On/Off
body: <p><em>I'm working with Unity 5.3 with C# as code editor</em></p>
  
  <p><strong>These are what I have :</strong></p>
  
  <p>I have 2 scenes in my project : <code>home</code> and <code>options</code>. I have <code>bg</code> object on both scenes. Both <code>bg</code> objects have <code>Audio Source</code> component, which contains same background music that <code>play on awake</code>. I don't use any codes for these background musics, I only click the <code>Add Component</code> button from Unity and add <code>Audio Source</code>.</p>
  
  <p><strong>This is what I want :</strong></p>
  
  <p><code>Options</code> scene can toggle the background music on/off for all scenes. Therefore, there are <code>btnOn</code> and <code>btnOff</code> in <code>Options</code> scene.</p>
  
  <p><strong>This is my code in Audio Manager.cs :</strong></p>
  
  <pre><code>using UnityEngine;
  using UnityEngine.UI;
  using System.Collections;
  
  public class AudioManager : MonoBehaviour {
      public Button btnOn;
      public Button btnOff;
  
      // Use this for initialization
      void Start () {
          btnOn = GetComponent&lt;Button&gt;();
          btnOff = GetComponent&lt;Button&gt;();
  
          btnOn.onClick.AddListener(() =&gt; PlayAudio());
          btnOff.onClick.AddListener(() =&gt; StopAudio());
      }
  
      void PlayAudio()
      {
          AudioSource.volume = 0.5f;
      }
  
      void StopAudio()
      {
          AudioSource.volume = 0f;
      }
  }
  </code></pre>
  
  <p><strong>This is the problem :</strong></p>
  
  <p>I have this error : <code>An object reference is required to access non-static member UnityEngine.AudioSource.volume</code>. Maybe, this is because I don't write <code>public AudioSource audioSource</code> in my code. But, if I write this, I have to add another audio in <code>Get Component</code> box, and I will have double <code>Audio Source</code> in one scene. What should I do? Thanks </p>