is there a trick to getting www to work
I'm using 2017.2.0f3 personal on linux and can't get urlrequest to work. I've tried everything I've been able to find searching the internet but can't get it to work. Is there some really obvious thing that everyone else knows but I don't?
The script should get a value from a local server but to attempt to eliminate possible errors I put a page on line with just a number on it and change the url to that. (you can check that that works in a browser). However the threaded function never gets past the yield line.
public class follower : MonoBehaviour {
...
public string URL = "https://www.eldwick.org.uk/files/val.txt";
...
void Update () {
if ((Time.time > last_speed_tm + DT) && !url_queried) {
StartCoroutine(WaitForRequest());
}
...
IEnumerator WaitForRequest() {
print("got here");
url_queried = true;
WWW www = new WWW(URL);
print("then here");
yield return www;
print("but never here");
speed = float.Parse(www.text);
print("speed " + speed);
last_speed_tm = Time.time;
url_queried = false;
}
}
I'd be grateful for any pointers.
Paddy
PS amongst the many things I've tried was the following commented out version of the coroutine method
/*url_queried = true;
using (UnityWebRequest www = UnityWebRequest.Get (URL)) {
print ("got here");
yield return www.Send ();
print ("but not here");
if (www.isNetworkError || www.isHttpError) {
print ("oops " + www.error);
} else {
speed = float.Parse(www.downloadHandler.text);
print("speed " + speed);
}
}
url_queried = false;
last_speed_tm = Time.time;
}*/
Yes, at one stage I thought I was onto something, but didn't seem to make any difference!
It works fine on my end, except I didn't use your Update method.
Answer by paddywwoof · Dec 15, 2017 at 12:16 PM
Aaaaarg. Just noticed the VERY annoying feature of Unity that public variables are set in the Editor Inspector panel so my changes to the URL in my script were being overwritten by the old (wrong) values. I have now gone through my scripts and changed all the
public float x = 0.0;
to
public float x;
what a waste of time.
I would advise to start debugging your code... Visual Studio integrates quite nicely with Unity and offers good debugging tools. If you were doing this you would notice immedietaly :)
Your answer
Follow this Question
Related Questions
how can I open url link in Unity/Vuforia android app 2 Answers
C# - Cannnot access variable in another script unless I get the component everytime. 1 Answer
Any easy way to choose the method called when clicking a button? 0 Answers
What is the new SceneManagement equivalent for Application.Quit? 1 Answer
Is it possible to use the job system to modify UI elements like text? If so, how? 0 Answers