Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using PlayFab;
- using PlayFab.ClientModels;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PlayFabPlayerStats1 : MonoBehaviour
- {
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- }
- public void SaveStats()
- {
- //Neue Anfrage erstellen
- var request = new UpdatePlayerStatisticsRequest();
- //Liste mit Statistiken
- request.Statistics = new List<StatisticUpdate>();
- //Neuen Wert für Statistik anlegen
- var stat = new StatisticUpdate { StatisticName = "Erfahrung", Value = 0 };
- var stat1 = new StatisticUpdate { StatisticName = "Titan", Value = 0 };
- var stat2 = new StatisticUpdate { StatisticName = "Orden", Value = 0 };
- var stat3 = new StatisticUpdate { StatisticName = "Wasser", Value = 0 };
- //Eintag hinzufügen
- request.Statistics.Add(stat);
- request.Statistics.Add(stat1);
- request.Statistics.Add(stat2);
- request.Statistics.Add(stat3);
- //Anfrage an PlayFab API starten
- PlayFabClientAPI.UpdatePlayerStatistics(request, OnStatsSuccess, OnPlayFabError);
- }
- private void OnPlayFabError(PlayFabError obj)
- {
- print("Es ist etwas im Stats-Script schiefgelaufen");
- }
- private void OnStatsSuccess(UpdatePlayerStatisticsResult obj)
- {
- print("Neue Statistik gespeichert");
- }
- public void GetStats()
- {
- //Neue Anfrage erstallen
- var request = new GetPlayerStatisticsRequest();
- // request an PlayFabAPI
- PlayFabClientAPI.GetPlayerStatistics(request, GetPlayerStaticsSuccess, OnPlayFabError);
- }
- private void GetPlayerStaticsSuccess(GetPlayerStatisticsResult obj)
- {
- print("Stats wurden erfolgreich empfangen");
- // Statisken ausgeben
- foreach (var stat in obj.Statistics)
- {
- print("Statistic:" + stat.StatisticName + "Wert:" + stat.Value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement