기술 자료

​
​

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 또는 그 계열사의 상표 또는 등록상표입니다(자세한 내용은 여기에서 확인하세요). 기타 명칭 또는 브랜드는 해당 소유자의 상표입니다.

일부 페이지는 편의를 위해 기계 번역되었으며 부정확한 내용이 있을 수 있습니다. 정보가 상충되는 경우, 영어 버전을 우선으로 참조하세요.


    이 페이지의 문제 보고