ドキュメント

​
​

Development

User Acquisition

Monetization

産業

Leaderboards

Unity SDK

Admin API

Client API

Open Unity Dashboard

Leaderboards

このページは選択した言語では使用できません。
LiveOps
​
​
Leaderboards
  • Overview
  • Get started
  • Concepts
  • Tutorials
    • Configuration
    • Unity SDK tutorial
    • Unity SDK sample
    • Cloud Code samples
  • Reference
  • Privacy and consent
  1. Leaderboards

Unity SDK sample

Refer to sample code that implements Leaderboards functionality in a Unity project.
読み終わるまでの所要時間 2 分
最終更新 9ヶ月前

This sample (with additional methods) is found as part of the Leaderboards SDK package by checking the box to include
Samples
when installing from the package manager.
The following example presumes the existence of a leaderboard with the ID
my-first-leaderboard
. You can create this from the Unity Dashboard.
The sample then initializes the Unity services and uses anonymous authentication to sign-in the player in the
Awake
lifecycle callback (see SDK Installation & Setup) and then uses the SDK to provide methods for interacting with the leaderboard data and printing it to the console.
using System.Collections.Generic;using System.Threading.Tasks; using Newtonsoft.Json;using Unity.Services.Authentication;using Unity.Services.Core;using Unity.Services.Leaderboards;using UnityEngine;public class LeaderboardsSample : MonoBehaviour{ // Create a leaderboard with this ID in the Unity Dashboard const string LeaderboardId = "my-first-leaderboard"; string VersionId { get; set; } int Offset { get; set; } int Limit { get; set; } int RangeLimit { get; set; } List<string> FriendIds { get; set; } async void Awake() { await UnityServices.InitializeAsync(); await SignInAnonymously(); } async Task SignInAnonymously() { AuthenticationService.Instance.SignedIn += () => { Debug.Log("Signed in as: " + AuthenticationService.Instance.PlayerId); }; AuthenticationService.Instance.SignInFailed += s => { // Take some action here... Debug.Log(s); }; await AuthenticationService.Instance.SignInAnonymouslyAsync(); } public async void AddScore() { var scoreResponse = await LeaderboardsService.Instance.AddPlayerScoreAsync(LeaderboardId, 102); Debug.Log(JsonConvert.SerializeObject(scoreResponse)); } public async void GetScores() { var scoresResponse = await LeaderboardsService.Instance.GetScoresAsync(LeaderboardId); Debug.Log(JsonConvert.SerializeObject(scoresResponse)); } public async void GetPaginatedScores() { Offset = 10; Limit = 10; var scoresResponse = await LeaderboardsService.Instance.GetScoresAsync(LeaderboardId, new GetScoresOptions{Offset = Offset, Limit = Limit}); Debug.Log(JsonConvert.SerializeObject(scoresResponse)); } public async void GetPlayerScore() { var scoreResponse = await LeaderboardsService.Instance.GetPlayerScoreAsync(LeaderboardId); Debug.Log(JsonConvert.SerializeObject(scoreResponse)); } public async void GetVersionScores() { var versionScoresResponse = await LeaderboardsService.Instance.GetVersionScoresAsync(LeaderboardId, VersionId); Debug.Log(JsonConvert.SerializeObject(versionScoresResponse)); }}

Copyright © 2026 Unity Technologies
法規事項プライバシーポリシークッキーDocumentation Terms of Use私の個人情報を販売または共有しないプライバシーに関する選択 (クッキー設定)

"Unity" の名称、Unity のロゴ、およびその他の Unity の商標は、米国およびその他の国における Unity Technologies またはその関係会社の商標または登録商標です (詳しくはこちら)。その他の名称またはブランドは該当する所有者の商標です。

一部のページは利便性向上のため機械翻訳を使用しており、内容に不正確な表現が含まれる場合があります。内容に齟齬または不一致が生じた場合は、英語版を正本とします。


    このページの問題を報告する