我在用Playfab制作排行榜时遇到问题,我不知道如何将我的游戏分数发送到Playfab中的排行榜
我不是专业的c#,这就是为什么我必须看Coco Code Youtube知道如何使排行榜在简单的方式。
我的代码:
这是我得分代码,它允许我每次从墙得分移动时得到得分数:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class score : MonoBehaviour
{
public static int Score = 0;
void Start()
{
Score = 0;
}
void Update()
{
GetComponent<UnityEngine.UI.Text>().text = Score.ToString();
}
}
这是我的PlayFabManager代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
public class PlayFabManager : MonoBehaviour
{
void Start()
{
Login();
}
void Login()
{
var request = new LoginWithCustomIDRequest
{
CustomId = SystemInfo.deviceUniqueIdentifier,
CreateAccount = true
};
PlayFabClientAPI.LoginWithCustomID(request, OnSuccess, OnError);
}
void OnSuccess(LoginResult result)
{
Debug.Log("Success login/account create!");
}
void OnError(PlayFabError error)
{
Debug.Log("Error while logging in/creating account!");
Debug.Log(error.GenerateErrorReport());
}
public void SendLeaderboard(int score)
{
var request = new UpdatePlayerStatisticsRequest
{
Statistics = new List<StatisticUpdate>
{
new StatisticUpdate
{
StatisticName = "PlatFormScore",
Value = score
}
}
};
PlayFabClientAPI.UpdatePlayerStatistics(request, OnLeaderboardUpdate, OnError);
}
void OnLeaderboardUpdate(UpdatePlayerStatisticsResult result)
{
Debug.Log("Successfull leaderboard send");
}
}
1条答案
按热度按时间qxsslcnc1#
进入Playfab网站--〉进入您的游戏工作室--〉点击设置图标--〉进入“标题设置”--〉点击标签API功能--〉从标题ENABLE API FEATURES--〉启用“允许客户端启用统计数据”--〉保存