Ishaq Benaissa

Ishaq Benaissa

  • NA
  • 2
  • 597

How to order script execution only if statement apply

Feb 18 2019 12:20 AM
I have two script Loading, and CheckNetwork how do I load the game only if the version of the game match
 
I would like the script to wait until CheckNetwork finished loading the url and got the result whether the version matched or not.
 
When the result match, continue loading, else pop up a text then on tap quit the app.
 
Loading:
  1. private Image progressBar;  
  2. private void Start()  
  3. {  
  4. StartCoroutine(LoadAsyncOperation());  
  5. }  
  6. IEnumerator LoadAsyncOperation()  
  7. {  
  8. AsyncOperation gameLevel = SceneManager.LoadSceneAsync(3);  
  9. while (gameLevel.progress < 1)  
  10. {  
  11. progressBar.fillAmount = gameLevel.progress;  
  12. yield return new WaitForEndOfFrame();  
  13. }  
CheckNetwork
  1. public string URL = "";  
  2. public string CurrentVersion;  
  3. string latestVersion;  
  4. public GameObject newVersionAvailable;  
  5. private void Start()  
  6. {  
  7. StartCoroutine(LoadTxtData(URL));  
  8. }  
  9. void CheckVersion()  
  10. {  
  11. if(CurrentVersion != latestVersion)  
  12. {  
  13. newVersionAvailable.SetActive(true);  
  14. }  
  15. else  
  16. {  
  17. newVersionAvailable.SetActive(false);  
  18. }  
  19. }  
  20. private IEnumerator LoadTxtData(string url)  
  21. {  
  22. UnityWebRequest www = UnityWebRequest.Get(url);  
  23. yield return www.SendWebRequest();  
  24. latestVersion = www.ToString();  
  25. CheckVersion();  
  26. }  
  27. public void OpenURL(string url)  
  28. {  
  29. Application.OpenURL(url);  
  30. }