snakes_mp/Assets/Scripts/Utils/WaitForGameEnd.cs
2025-04-14 11:36:17 +05:30

40 lines
954 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaitForGameEnd : MonoBehaviour
{
public GameObject[] loading;
public GameObject[] gameEnd;
void Start()
{
StartCoroutine(PollUntilGameEnd());
}
IEnumerator PollUntilGameEnd()
{
string response = "0";
SetActiveAll(loading, true);
SetActiveAll(gameEnd, false);
while(response == "0")
{
WWW www = new WWW(Constants.API_URL + $"get_game_completed.php?address={GameData.address}");
yield return www;
response = www.text;
yield return new WaitForSeconds(1f);
}
SetActiveAll(loading, false);
SetActiveAll(gameEnd, true);
}
void SetActiveAll(GameObject[] gameObjects, bool active)
{
foreach (var gameObject in gameObjects)
{
gameObject.SetActive(active);
}
}
}