c# - Waiting for web call to finish before continuing code in Unity3d -


i've read many articles don't seem it. have code working because hardcode 3 second delay there enough time web call finish when score displayed there data. want have web call finish , display score. ?

 ienumerator start() {     client = new mobileserviceclient(_appurl, _appkey);     table = client.gettable<highscore>("highscores");     yield return startcoroutine(readitems());     displayscores(); }  void update() {  }  public void btn_goback() {     application.loadlevel("startscene"); }  private void onreaditemscompleted(irestresponse<list<highscore>> response) {     if (response.statuscode == httpstatuscode.ok)     {         debug.log("onreaditemscompleted data: " + response.content);         list<highscore> items = response.data;         debug.log("read items count: " + items.count);         scores = items;     }     else     {         debug.log("error status:" + response.statuscode + " uri: " + response.responseuri);     } }  private ienumerator readitems() {     table.read<highscore>(onreaditemscompleted);     yield return new waitforseconds(3); }  private void displayscores() {     txthighscores.text = "";     int numberofscores = math.min(scores.count, 5);      (int = 0; < numberofscores; i++)     {         string name = scores[i].username.tostring();         string score = scores[i].score.tostring();          txthighscores.text += (i + 1).tostring() + ". " +                               " - " + name + "\r\n" +                               score.tostring().padleft(4, '0');     } } 

it important pass parameter startcorutine method, otherwise gives error. try fix in code.

 ienumerator start() {     client = new mobileserviceclient(_appurl, _appkey);     table = client.gettable<highscore>("highscores");     yield return startcoroutine(readitems(2.0f)); //delay     displayscores(); }  ienumerator readitems(float delay) {     yield return new waitforseconds(delay);     table.read<highscore>(onreaditemscompleted);  } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -