Functions do not wait for coroutines before returning, however you can use Action to give some kind of return.
Put this in your Start function
WWW www = new WWW("http://google.com"); StartCoroutine(WaitForRequest(www,(status)=>{ print(status.ToString()); }));
and add this.
private IEnumerator WaitForRequest(WWW www,Action<int> callback) { int tempInt = 0; yield return www; if (string.IsNullOrEmpty(www.error)) { if(!string.IsNullOrEmpty(www.text)) { tempInt = 3; } else { tempInt=2; } } else { print(www.error); tempInt=1; } callback(tempInt); }
Try this attempt, although the function can change a value that does not return a value and has only one parameter. Thus, in fact, this is not a solution for returning your coroutine, however, after receiving the int from the coroutine, which we can then justify what to do with it, and even call other functions from the callback.
StartCoroutine(WaitForRequest(www,(status)=>{ print(status.ToString()); Awake(); // we can call other functions within the callback to use other codeblocks and logic. if(status != 0) print("yay!"); } ));
It may come in handy for you. http://answers.unity3d.com/questions/744888/returning-an-ienumerator-as-an-int.html
source share