title: How do I get a value from another script in Unity (with an IEnumerator)?
body: <p>I want to get a value in a script from a different script. I have two scripts:</p>
  
  <pre><code>public class CargarDatos : MonoBehaviour
  {
      public string[] fechas;
      public string dia;
  
      IEnumerator Start()
      {
          UnityWebRequest www = UnityWebRequest.Get("http://localhost/Linx/Fechas.php");
          yield return www.SendWebRequest();
          string fechasDatos = www.downloadHandler.text;
          print(fechasDatos);
          fechas = fechasDatos.Split(';');
          dia = GetValorDatos(fechas[0], "Dia:");
          //print(dia);
      }
  
      string GetValorDatos(string datos, string index)
      {
          string valor = datos.Substring(datos.IndexOf(index)+index.Length);
          if(valor.Contains("|"))
          {
             valor = valor.Remove(valor.IndexOf("|")); 
          }
          return valor;
      }
  }
  </code></pre>
  
  <p>Here, as it is shown, a connection is established to a database and get a value (dia). This script is attached to the Main Camera, as I only want it to connect at the start of the game. Here, the function print(dia) returns the correct value, so this script works.</p>
  
  <p>The problem is when I try to get the value in this script:</p>
  
  <pre><code>public class BarraExperiencia : MonoBehaviour
  {
      void Start()
      {
          print(GameObject.Find("Main Camera").GetComponent&lt;CargarDatos&gt;().dia);
      }
  }
  </code></pre>
  
  <p>This script is attached to a slider, and I have tried to print that to see if it works, but it doesn't print anything. What have I done wrong? Thanks.</p>