Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
public class test : MonoBehaviour
{
// Start is called before the first frame update
List<string> ids ;
bool flag = false;
void Start()
{
PlayFabSettings.DeveloperSecretKey = "xxxxx";
PlayFabSettings.TitleId = "xxxxx";
PlayFabServerAPI.GetPlayersInSegment(
new PlayFab.ServerModels.GetPlayersInSegmentRequest
{
SegmentId = "xxx",
MaxBatchSize = 40,
SecondsToLive = 10
},
onsuccess =>
{
foreach (var id in onsuccess.PlayerProfiles)
{
ids.Add(id.PlayerId);
}
StartCoroutine("setstatistics");
},
onfail=> { });
}
IEnumerator setstatistics()
{
for (int i = 0; i < ids.Count; i++)
{
flag = false;
PlayFabServerAPI.UpdatePlayerStatistics(
new PlayFab.ServerModels.UpdatePlayerStatisticsRequest
{
Statistics = new List<PlayFab.ServerModels.StatisticUpdate> {
new PlayFab.ServerModels.StatisticUpdate{
StatisticName = "Points",
Value = Random.Range(1,500 )
}
},
PlayFabId = ids[i]
},
sucess => { print(i + " : "+ids[i]); flag = true; },
fail=> { print(fail.GenerateErrorReport()); flag = true; });
yield return new WaitUntil (()=> flag == true);
}
}
// Update is called once per frame
void Update()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment