Skip to content
Snippets Groups Projects
WaitingForLocalMMT.cs 1.95 KiB
Newer Older
using UnityEngine;
MaZiFAU's avatar
MaZiFAU committed
using UnityEngine.SceneManagement;

public class WaitingForLocalMMT : MonoBehaviour
{

    private void Start()
    {
    }

    private void Update()
    {

    }
    private void OnEnable()
    {
        StartCoroutine(ServerRoutine());
    }

    private void OnDisable()
    {
        StopCoroutine(ServerRoutine());
    }

    void PrepareGame()
    {
        if (true)
        {
            CommunicationEvents.ServerRunning = true;
        if (CommunicationEvents.ServerRunning == true)
        {
            CommunicationEvents.ServerAdress = CommunicationEvents.ServerAddressLocal;
Stefan Richter's avatar
Stefan Richter committed
            //UnityEngine.Debug.Log("StartMainMenu");
            SceneManager.LoadScene("MainMenu");
MaZiFAU's avatar
MaZiFAU committed

            using UnityWebRequest request = pingL();
            yield return request.SendWebRequest();
            if (request.result == UnityWebRequest.Result.ConnectionError
             || request.result == UnityWebRequest.Result.ProtocolError)
            {
                // UnityEngine.Debug.Log("no running server");
            }
            else
            {
                //break;
                PrepareGame();
            }

            //Wait for 2 seconds
            yield return new WaitForSecondsRealtime(2f);

    public UnityWebRequest pingL()
    {
        //UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
        //using UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list");
        UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/fact/list");
        return request;
    }