title: Unity Check if Toggle isOn
body: <p>I am checking to see if a toggle is on. Normally I use <code>public Toggle myToggle</code> in the inspector but this this I am attaching the script to the <code>Toggle</code> and probably wrongly using <code>GetComponent&lt;Toggle&gt;()</code></p>
  
  <p>I get <code>NullReferenceException: Object reference not set to an instance of an object</code> on the <code>if(m_Toggle.isOn)</code> line.</p>
  
  <p>This is the script attached to the <code>Toggle</code></p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  
  public class ToggleSound : MonoBehaviour {
  
      Toggle m_Toggle;
  
      // Use this for initialization
      void Start () {
          m_Toggle = GetComponent&lt;Toggle&gt;();
          Debug.Log(m_Toggle);
  
      }
  
      public ToggleSound ()
      {
          if(m_Toggle.isOn)
          {
              AudioManager.Instance.SetVolume(0, -80);
          }
          else
          {
              AudioManager.Instance.SetVolume(0, 0);
          }
      }
  }
  </code></pre>