c# - 在 Unity 2017.3.1f 中找不到排行榜
问题描述
因此,我正在尝试为我计划在 Android 上发布的游戏添加排行榜。我在尝试访问游戏中的排行榜时收到一条错误消息,提示“未找到排行榜”。即使我仔细检查了排行榜按钮的名称,我也会收到另一个错误,即“对象引用未设置为对象”,并且我将指定此错误出现的行。我还将指定排行榜错误发送给我的行。这是我到目前为止编写的代码:
using GooglePlayGames;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.UI;
public class LeaderboardController : MonoBehaviour {
public static LeaderboardController instance;
private const string ID = ".......";
public UnityEngine.UI.Button LeaderboardsButton;
// Use this for initialization
void Awake () {
MakeSingleton();
GetTheButton();
}
void GetTheButton()
{
//this line is the problem about object reference.
LeaderboardsButton = GameObject.Find("Leaderboards").GetComponent<UnityEngine.UI.Button>();
LeaderboardsButton.onClick.RemoveAllListeners();
LeaderboardsButton.onClick.AddListener(() => OpenLeaderBoardsScore());
}
// Update is called once per frame
void Start(){
PlayGamesPlatform.Activate();
}
void OnLevelWasLoaded()
{
PostScore();
}
void MakeSingleton()
{
if(instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
}
}
public void OpenLeaderBoardsScore()
{
if (Social.localUser.authenticated)
{
PlayGamesPlatform.Instance.ShowLeaderboardUI(ID);
}
else
{
Social.localUser.Authenticate((bool success) =>
{
});
}
}
void PostScore()
{
//this is the line that Leaderboard error sends me.
if (Social.localUser.authenticated)
{
Social.ReportScore(PlayerPrefs.GetInt("Score"), ID, (bool success) =>{
});
}
}
}
解决方案
推荐阅读
- javascript - 外部 JavaScript 文件中的函数不会运行 OnClick
- unicode - Azure 服务总线消息触发 Azure 函数(unicode 消息)
- flutter - flutter_form_builder 以编程方式设置字段的值不起作用
- python - 将 numpy 数组中的所有像素替换为单独数组中的像素,除非值为 0
- javascript - 使用空系列线数据连接 3 个不同的 echart 图表
- r - 关于条形图的格式问题
- node.js - 节点服务器没有响应
- r - 如何使用 R 重新排列表格
- android - 如何在android Q中获取唯一ID?卸载和安装应用程序时必须相同
- couchbase - Couchbase XDCR 迁移