Quantcast
Channel: Answers by "hangemhigh"
Viewing all articles
Browse latest Browse all 35

Answer by hangemhigh

$
0
0
Maybe WWW is not done before you accessed it. Try this WWW cityRequest; // Use this for initialization void Start () { StartCoroutine(getCityInfo()); } // Update is called once per frame void Update () { if(cityRequest.isDone){ showResult(); } } IEnumerator getCityInfo(){ cityRequest = new WWW ("http://www.geoplugin.net/json.gp?ip=" + currentIP); //get player location //Wait until the info is done receing bytes while(!cityRequest.isDone){ yield return null; } } void showResult(){ if(cityRequest != null && cityRequest.isDone){ var N = JSON.Parse (cityRequest.text); currentCity = N ["geoplugin_city"].Value; currentCountry = N ["geoplugin_countryName"].Value; currentLon = N ["geoplugin_latitude"].Value; currentLat = N ["geoplugin_longitude"].Value; string shortLon = currentLon.Substring (0, 2); string shortLat = currentLat.Substring (0, 2); } } Or maybe you have trailing characters in the string. Use shortLon.Trim() and shortLat.Trim() to remove the leading and trailing white space then try the Substring function again.

Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>