Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine.Networking;
- using System.Collections;
- public class ServerValidation : MonoBehaviour
- {
- string serverURL = "https://your-server.com/validate";
- void Start()
- {
- StartCoroutine(ValidateWithServer());
- }
- IEnumerator ValidateWithServer()
- {
- // Assuming you send device ID or user ID to your server for validation
- UnityWebRequest www = UnityWebRequest.Get(serverURL + "?deviceId=" + SystemInfo.deviceUniqueIdentifier);
- yield return www.SendWebRequest();
- if (www.isNetworkError || www.isHttpError)
- {
- Debug.LogError("Error connecting to server: " + www.error);
- // Decide whether to let the user proceed or not
- }
- else
- {
- Debug.Log("Server validation successful: " + www.downloadHandler.text);
- // Handle server response (e.g., validation success or failure)
- if (www.downloadHandler.text != "OK")
- {
- Debug.LogError("Validation failed. Exiting game.");
- Application.Quit();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement