Hello! I have an issue, once i get response from SQL DB by www or UnityWebRequest i need to get my game waiting responce frome server and after get continue! for example i need to upgrade my weapon from +0 to +1 after i press upgrade button my game for player will stopped (freeze) until send request to DB update my weapon field and when i get response that it’s done my game will continue! If i do this by Enumerator I’ll get the opposite effect If don’t use my game does not have time to get response! Please help me!
How about posting the code for this, so we might havea a clue what’s going on and can help you?
For now I just can suggest that you use yield return webResponse; after you’ve send out the request in your IEnumerator, and then simple do your actions after the yield return, as the function will wait for response. You could set a variable like paused = true/false to stop all other actions, and only run them when paused == false. I could imagine that freezing the game with Time.timeScale = 0; could also affect the IEnumerator, but I’m not sure, you have to try it.
Thx btw
and my simple code
string url = "http://localhost/project_4";
IEnumerator Start()
{
WWW www = new WWW(url);
yield return www;
string json = www.text;
Debug.Log(www.size);
}
I don’t know if the name Start() for your method causes any problems with the normal Start() Method that get’s triggery by Unity, so you might want to change it’s name. Also, as I already mentioned, if you want to pause the Game use a variable to check wether you’re waiting for response or already got your informations…
IEnumerator GetJson()
{
isPaused = true;
var www = new WWW(url);
yield return www;
isPaused = false;
var json = www.text;
Debug.Log(www.size);
}
You need to setup that “isPaused” variable (bool) as a static variable so you can access it from everywhere (or place it in one of your managers that you might use) and then simply check on your main features if the game is paused, before doing actions (you might also try timeScale, as written above, maybe this works too, and it saves you some code changes as it just needs to be places in the GetJson function here, instead of the isPaused code lines…)