I am making a VR game. I have a scene that the player automatically goes to if they are banned (PlayFab.) I also have two Text Mesh Pro text boxes in the scene. I am trying to make a script that will put the time remaining on the player’s ban in one, and the reason for the ban in the other. I know it is possible, but I am pretty new around here and it is a bit confusing since the player can’t log into PlayFab (Because they are banned.) Here is the script that I currently have, but it does not function. Do you guys have any suggestions or know where I can go to get more help?
Here is the current script I have:
using System;
using System.Globalization;
using UnityEngine;
using PlayFab;
using TMPro;
using Photon.VR;
public class BanManager : MonoBehaviour
{
[Header("BAN CONFIGURATION")]
public GameObject[] StuffToDisable;
public GameObject[] StuffToEnable;
public MeshRenderer[] StuffToMaterialChange;
public Material MaterialToChangeToo;
public TextMeshPro[] BanTimes;
public TextMeshPro[] BanReasons;
// This method handles the ban based on the error details returned from PlayFab
public void HandleBan(PlayFabError error)
{
if (error.Error == PlayFabErrorCode.AccountBanned)
{
// Disconnect the player
PhotonVRManager.Manager.Disconnect();
// Disable specific game objects
foreach (GameObject obj in StuffToDisable)
{
obj.SetActive(false);
}
// Enable other game objects
foreach (GameObject obj in StuffToEnable)
{
obj.SetActive(true);
}
// Change the material of specific objects
foreach (MeshRenderer rend in StuffToMaterialChange)
{
rend.material = MaterialToChangeToo;
}
// Update ban time and reason in the UI
foreach (var item in error.ErrorDetails)
{
UpdateBanTime(item.Value[0]); // Update the time left for the ban
UpdateBanReason(item.Key); // Display the ban reason
}
}
}
private void UpdateBanTime(string playFabTime)
{
foreach (TextMeshPro BanTime in BanTimes)
{
if (playFabTime == "Indefinite")
{
BanTime.text = "Permanent Ban";
}
else
{
try
{
DateTime unityTime = DateTime.ParseExact(playFabTime, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture);
TimeSpan timeLeft = unityTime.Subtract(DateTime.UtcNow);
int hoursLeft = (int)timeLeft.TotalHours;
BanTime.text = string.Format("Hours Left: {0}", hoursLeft);
}
catch (FormatException ex)
{
Debug.LogErrorFormat("Failed to parse PlayFab time '{0}': {1}", playFabTime, ex.Message);
}
}
}
}
private void UpdateBanReason(string reason)
{
foreach (TextMeshPro BanReason in BanReasons)
{
BanReason.text = string.Format("Reason: {0}", reason);
}
}
}