Newer
Older
Stefan Richter
committed
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
Stefan Richter
committed
using UnityEngine.Networking;
using static UIconfig;
public class WaitingForLocalMMT : MonoBehaviour
{
private void Start()
{
Stefan Richter
committed
//StartCoroutine(ServerRoutine());
}
private void Update()
{
Stefan Richter
committed
}
private void OnEnable()
{
StartCoroutine(ServerRoutine());
}
private void OnDisable()
{
StopCoroutine(ServerRoutine());
}
void PrepareGame()
{
if (true)
{
CommunicationEvents.ServerRunning = true;
UnityEngine.Debug.Log("set server runs");
}
if (CommunicationEvents.ServerRunning == true)
{
CommunicationEvents.ServerAdress = CommunicationEvents.ServerAddressLocal;
UnityEngine.Debug.Log("StartMainMenue");
SceneManager.LoadScene("MainMenue");
}
Stefan Richter
committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
}
IEnumerator ServerRoutine()
{
while (true)
{
UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list");
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);
print("waiting");
yield return null;
}