# NerdRank SDK for Unity

Small Unity client for the NerdRank leaderboard API.

## Install

This project includes the SDK as an embedded Unity package at:

`Packages/com.nerdrank.sdk`

Unity should detect it automatically after the project reloads.

## Usage

```csharp
using NerdRank;
using UnityEngine;

public class ScoreSubmitter : MonoBehaviour
{
    [SerializeField] private NerdRankSettings settings;
    [SerializeField] private string leaderboardId;
    [SerializeField] private string userId; // Guid

    private NerdRankClient client;

    private void Awake()
    {
        client = new NerdRankClient(settings);
    }

    public void SubmitScore()
    {
        StartCoroutine(client.AddLeaderboardEntry(
            leaderboardId,
            "Player",
            12345,
            System.Guid.NewGuid().ToString(),
            result =>
            {
                if (result.Success)
                {
                    Debug.Log($"Submitted score entry {result.Value.id}");
                }
                else
                {
                    Debug.LogError(result.Error);
                }
            }));
    }
}
```

## User ID & Player Name
You should use a userId associated with the SaveFile, and use the same user id for that profile. 

For player name, get from the console or pc.

## API

Submit a score:

```csharp
StartCoroutine(client.AddLeaderboardEntry(leaderboardId, playerName, score, userId, callback));
```

Retrieve a leaderboard with entries:

```csharp
StartCoroutine(client.GetLeaderboard(leaderboardId, entriesToRetrieve, callback));
```

The API key is sent as the `X-API-Key` header. Keep production API keys out of public client builds when possible.

Get the API-Key for your leaderboard at NerdRanks.com
