本主題說明如何在 Unity 遊戲中使用 Play 遊戲服務成就。本文假設您已設定專案和 Unity 專用 Google Play 遊戲外掛程式,詳情請參閱入門指南。
建立成就
設定專案和外掛程式時,請在 Google Play 管理中心建立成就,然後使用 Android 資源,為您的成就更新外掛程式。如要進一步瞭解如何在 Play 管理中心內建立成就,請參閱成就指南」。
顯示並解鎖成就
如要解鎖成就,請使用 Social.ReportProgress 方法與 100.0f 的進度值:
usingGooglePlayGames;usingUnityEngine.SocialPlatforms;...// unlock achievement (achievement ID "Cfjewijawiu_QA")Social.ReportProgress("Cfjewijawiu_QA",100.0f,(boolsuccess)=>{// handle success or failure});
如果成就為遞增性質,Social.ReportProgress 的 Play 遊戲實作項目會嘗試依據 Unity 的 Social API 採取預期行為。行為不一定會相同,因此建議您不要使用 Social.ReportProgress 來實作遞增成就,改用 PlayGamesPlatform.IncrementAchievement 方法 (此為 Play 遊戲擴充功能)。
usingGooglePlayGames;usingUnityEngine.SocialPlatforms;...// increment achievement (achievement ID "Cfjewijawiu_QA") by 5 stepsPlayGamesPlatform.Instance.IncrementAchievement("Cfjewijawiu_QA",5,(boolsuccess)=>{// handle success or failure});
顯示成就 UI
如要顯示所有成就的內建 UI,請呼叫 Social.ShowAchievementsUI。
usingGooglePlayGames;usingUnityEngine.SocialPlatforms;...// show achievements UISocial.ShowAchievementsUI();
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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();"]]