title: Unity C# how to share data across classes?
body: <p>I am trying to develop a unity game whereby the user moves objects around accoding to data entered into a texbox. But I am unable to make the data from a textbox apply to an object that I want to move.
  Here is C# script for the textbox:</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class ButtonText : MonoBehaviour
  {
  
  private bool defineModel = false;
      string beta = "";
      public float number ;
      bool res ;
  
      void OnGUI()
      {
          if (!defineModel) {
                  if (GUI.Button (new Rect (0, 0, 150, 20), "Define a shift"))
                                  defineModel = true;
                } else {  
                          beta = GUI.TextField (new Rect (250, 157, 250, 25), beta, 40);
                           res = float.TryParse(beta, out number); 
                           if (res == false) { print("String is not a number");  }
                           else { number = float.Parse(beta);  }
  
                      if (GUI.Button (new Rect (300, 250, 100, 30), "OK")) {
                              if(!res) return;
                  else { Debug.Log (" number = "  + number);
                                  defineModel = false;
                                  return; }
  
                          }
                  }
  
      }
  </code></pre>
  
  <p>and here is script to create a sphere to be moved during the game</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class CloneSphere : MonoBehaviour 
  {
      public GameObject sphere;
      void Start() 
      {
          GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Make a new sphere
          sphere.name = "Sphere"; // give it a name
          sphere.transform.position = new Vector3(0, 0, 0); // position the sphere
          }
      float number;
  
      void Update () {
      sphere = GameObject.Find("Sphere");
          float location = GetComponent&lt;ButtonText&gt;().number ;
          sphere.transform.Translate(0, location ,0, Space.World); 
      }
  }
  </code></pre>
  
  <p>The last two lines of the latter script generate an error (i.e., if I comment these two lines out, there is no error):
  NullReferenceException: Object reference not set to an instance of an object.
  CloneSphere.Update () (at Assets/CloneSphere.cs:20)</p>
  
  <p>What is wrong here? How can I make this number "location" apply to the vertical shift of the sphere? </p>