title: Unity On Click error
body: <p>TowerSelection class I think is working fine.</p>
  
  <pre><code> public class TowerSelection : MonoBehaviour {
  
          public GameObject towerType;
  
          void Start()  {}
  
          void Update() {
          }
  
          public void TowerType (GameObject prefab) {
              towerType = prefab;
              Debug.Log (towerType.name);
          }
  
      }
  </code></pre>
  
  <p>TowerSpot class,  the problem is in OnMouseUp Method at  " prefabTower = GameObject.FindObject ... "</p>
  
  <pre><code>public class TowerSpot : MonoBehaviour {
  
      private GameObject prefabTower;
  
      private GameObject tower;
      private int gold;
  
      // Use this for initialization
      void Start () {
  
      }
  
      // Update is called once per frame
      void Update () {
  
      }
  
      public void OnMouseUp()
      {
          if (placeTower())
          {
  
              **prefabTower = GameObject.FindObjectOfType&lt;TowerSelection&gt;().towerType;**
  
              Debug.Log (prefabTower.name);
  
              gold = GameManager.Manager.getGold();
  
              if (gold &gt; 0)
              {
                  Instantiate( prefabTower , this.transform.position, this.transform.rotation);
                  GameManager.Manager.currentGold(-20);
              }
              else
              {
                  Debug.Log("No hay suficiente dinero");
              }
  
          }
  
  
      }
  
      private bool placeTower()
      {
          return tower == null;
      }
  }
  </code></pre>
  
  <p>This is the line I think it is returning "NULL", I have tried doing a lot of things but the error continues.</p>
  
  <pre><code>prefabTower = GameObject.FindObjectOfType&lt;TowerSelection&gt;().towerType;
  </code></pre>
  
  <p>The error is this one, Object reference not set to an instance of an object.</p>
  
  <p>What I am doing is a tower defence game, I have 2 buttons depending on what tower I am selecting, tower 1 or tower 2, using On Click in the inspector I call the TowerType method and I add the tower's Prefab, but when using the method FindObjectOfType&lt;>() It returns null everytime, and I dont know why.</p>
  
  <p>Any idea?</p>