Newer
Older
Stefan Richter
committed
using System.Collections;
Stefan Richter
committed
using UnityEngine.Networking;
using static CommunicationEvents;
public class WaitingForLocalMMT : MonoBehaviour
{
Stefan Richter
committed
private void OnEnable()
{
StartCoroutine(ServerRoutine());
}
private void OnDisable()
{
StopCoroutine(ServerRoutine());
}
void PrepareGame()
{
//This condition should always be true if PrepareGame gets called, but it never hurts to make sure.
if (CommunicationEvents.ServerRunning)
Stefan Richter
committed
{
CommunicationEvents.ServerAdress = "http://" + CommunicationEvents.ServerAddressLocal; //ServerAddress needs the "http://"
//UnityEngine.Debug.Log("StartMainMenu");
SceneManager.LoadScene("MainMenu");
Stefan Richter
committed
}
IEnumerator ServerRoutine()
{
while (true)
{
yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: false);
Stefan Richter
committed
// The address of the localServer currently cannot change, so it is never empty/illegal
// If this can happen in the future, this condition may not suffice
if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.online)
Marco Zimmer
committed
{
CommunicationEvents.ServerRunning = true;
Marco Zimmer
committed
PrepareGame();
}
//Wait for 2 seconds
yield return new WaitForSecondsRealtime(2f);
Stefan Richter
committed
print("waiting");
}
public UnityWebRequest pingL()
{
//UnityWebRequest request = UnityWebRequest.Get("http://" + NetwAddress + "/scroll/list");
//using UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAddressLocal + "/scroll/list");
UnityWebRequest request = UnityWebRequest.Get("http://" + CommunicationEvents.ServerAddressLocal + "/fact/list");