Unity 游戏中的成就
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本主题介绍了如何在 Unity 游戏中使用 Play 游戏服务成就,并假定您已按照入门指南中的说明设置您的项目和适用于 Unity 的 Google Play 游戏插件。
创建成就
在设置项目和插件时,请在 Google Play 管理中心内创建成就,然后使用适用于您的成就的 Android 资源更新插件。如需详细了解如何在 Play 管理中心内创建成就,请参阅成就指南。
显示和解锁成就
如需解锁成就,请使用进度值为 100.0f 的 Social.ReportProgress 方法:
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
...
// unlock achievement (achievement ID "Cfjewijawiu_QA")
Social.ReportProgress("Cfjewijawiu_QA", 100.0f, (bool success) => {
// handle success or failure
});
根据 Social.ReportProgress 的预期行为,值为 0.0f 表示已显示成就,进度为 100.0f 表示已解锁成就。
如需显示某项成就(之前处于隐藏状态)而不解锁该成就,只需调用值为 0.0f 的 Social.ReportProgress 即可。
分步成就
对于分步成就,Social.ReportProgress 的 Play 游戏实现会尝试依据 Unity 的 Social API 以遵循预期行为。不过,行为可能不完全相同,因此我们建议不要使用 Social.ReportProgress 来实现分步成就。请改用 PlayGamesPlatform.IncrementAchievement 方法,这是一项 Play 游戏扩展。
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
...
// increment achievement (achievement ID "Cfjewijawiu_QA") by 5 steps
PlayGamesPlatform.Instance.IncrementAchievement(
"Cfjewijawiu_QA", 5, (bool success) => {
// handle success or failure
});
显示成就界面
如需显示所有成就的内置界面,请调用 Social.ShowAchievementsUI。
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
...
// show achievements UI
Social.ShowAchievementsUI();
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Achievements in Unity games\n\nThis topic describes how to use Play Games Services achievements in Unity\ngames. It assumes that you've set up your project and the\nGoogle Play Games plugin for Unity, as discussed in the\n[Get started guide](/games/pgs/unity/unity-start).\n\nCreate an achievement\n---------------------\n\nWhen you set up your project and plugin, create the achievements in\nGoogle Play Console and then update the plugin with the Android resources\nfor your achievements. For details about creating achievements in\nPlay Console, see the\n[achievements guide](/games/pgs/achievements#create_an_achievement).\n\nReveal and unlock an achievement\n--------------------------------\n\nTo unlock an achievement, use the **Social.ReportProgress** method with a\nprogress value of 100.0f: \n\n using GooglePlayGames;\n using UnityEngine.SocialPlatforms;\n ...\n // unlock achievement (achievement ID \"Cfjewijawiu_QA\")\n Social.ReportProgress(\"Cfjewijawiu_QA\", 100.0f, (bool success) =\u003e {\n // handle success or failure\n });\n\nAccording to the expected behavior of\n[Social.ReportProgress](http://docs.unity3d.com/Documentation/ScriptReference/Social.ReportProgress.html),\na value of 0.0f means the achievement is revealed and a progress of 100.0f\nmeans the achievement is unlocked.\n\nTo reveal an achievement that was\npreviously hidden without unlocking it, call **Social.ReportProgress** with\na value of 0.0f.\n\nIncrement an achievement\n------------------------\n\nIf the achievement is incremental, the Play Games implementation of\n**Social.ReportProgress** will try to adhere to the\nexpected behavior according to Unity's social API. The behavior might not be\nidentical, though, so we recommend that you don't use **Social.ReportProgress**\nfor incremental achievements. Instead, use the\n[PlayGamesPlatform.IncrementAchievement](/games/services/unity/v2/api/class/google-play-games/play-games-platform#incrementachievement) method, which is a\nPlay Games extension. \n\n using GooglePlayGames;\n using UnityEngine.SocialPlatforms;\n ...\n // increment achievement (achievement ID \"Cfjewijawiu_QA\") by 5 steps\n PlayGamesPlatform.Instance.IncrementAchievement(\n \"Cfjewijawiu_QA\", 5, (bool success) =\u003e {\n // handle success or failure\n });\n\nShow the achievements UI\n------------------------\n\nTo show the built-in UI for all achievements, call\n**Social.ShowAchievementsUI**. \n\n using GooglePlayGames;\n using UnityEngine.SocialPlatforms;\n ...\n // show achievements UI\n Social.ShowAchievementsUI();"]]