So what I am trying to do is, when I call the method in another class, I want to get the int from the coroutine, but I have hit a road block on how to do this. As you can see below I tried to do it, but I just can’t figure it out.
Eventually I want to store the int into a playerpref.
using UnityEngine;
using System.Collections;
public class TimerController : MonoBehaviour
{
private string url = "mywebsite"; //timer php url
public int unixTimeSeconds;
void Start ()
{
}
public void RequestTime()
{
StartCoroutine(GetTime());
}
public int ReturnTime(string urlwwwtext)
{
unixTimeSeconds = int.Parse(urlwwwtext);
return unixTimeSeconds;
}
public IEnumerator GetTime()
{
WWW urlwww = new WWW(url);
yield return urlwww;
if (string.IsNullOrEmpty(urlwww.error))
{
//Debug.Log("server time: " + urlwww.text); //gets current unix timestamp since January 1, 1970
//yield return urlwww.text;
ReturnTime(urlwww.text);
}
else
{
Debug.Log("could not connect to my website, retrying");
StartCoroutine(GetTime());
}
}
}