locked
How can I make a C# sharp script execute in a certain order? Unity3d RRS feed

  • Question

  • I have two scripts that checks if there is network connection and the version of the game (if it's up to date) and then load the game but it's not working properly

    How do I make it follow this pattern?:

    1. Check if there is internet connection
    2. Check the version of the game
    3. Only load the game if there is an internet connection and the version of the game is up to date

    CheckNetwork.cs

        public Text AlertText;
        public GameObject alert;
    
        public string URL = "";
        public string CurrentVersion;
        string latestVersion;
        public GameObject newVersionAvailable;
    
        private void Start()
        {
            StartCoroutine(LoadTxtData(URL));
        }
        void Awake()
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                alert.SetActive(true);
                AlertText.text = "Sorry, you have to enable your conection to play this game";
                if (Input.GetKey(KeyCode.Escape))
                    Application.Quit();
                 if (Input.GetKey(KeyCode.Escape))
                    {
                        Application.Quit();
                    }
            }
            else
            {
                alert.SetActive(false);
            }
        }
        public void CheckVersion()
        {
            if(CurrentVersion != latestVersion)
            {
                newVersionAvailable.SetActive(true);
            }
            else
            {
                newVersionAvailable.SetActive(false);
            }
        }
        private IEnumerator LoadTxtData(string url)
        {
            UnityWebRequest www = UnityWebRequest.Get(url);
            yield return www.SendWebRequest();
            latestVersion = www.ToString();
            CheckVersion();
    
        }
        public void OpenURL(string url)
        {
            Application.OpenURL(url);
        }

    Loading.cs

        private Image progressBar;
        private void Start()
        {
            
            StartCoroutine(LoadAsyncOperation());
        }
        public IEnumerator LoadAsyncOperation()
        {
                AsyncOperation gameLevel = SceneManager.LoadSceneAsync(1);
                while (gameLevel.progress < 1)
                {
                    progressBar.fillAmount = gameLevel.progress;
                    yield return new WaitForEndOfFrame();
                }
            }

    • Moved by CoolDadTx Monday, March 25, 2019 2:41 PM Third party product
    Saturday, March 23, 2019 6:39 PM

All replies

  • This forum is for C#-specific questions only. Please post questions related to third party products like Unity in their forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, March 25, 2019 2:40 PM
  • oh. thank you

    Monday, March 25, 2019 3:39 PM