# Nakama Tournaments Sample Project

**URL:** https://heroiclabs.com/docs/sample-projects/unity/nakama-tournaments/
**Summary:** Nakama Tournaments sample project for Unity games
**Keywords:** nakama tournaments, unity sdk, score submissions, authentication, tournament leaderboards, device authentication, nakama tournaments controller, joining tournaments, record pagination, tournament ranking
**Categories:** unity, sample-projects, nakama-tournaments

---


## Code overview

The core scripts live under **Scripts**:

- `NakamaTournamentsController.cs` — handles auth, tournament listing, joining, record pagination, and score submissions.
- `TournamentView.cs` — renders a tournament listing (title, size/max counts, time remaining).
- `TournamentRecordView.cs` — renders a record (rank, username, score, sub-score).

#### Main controller (`NakamaTournamentsController.cs`)

Connects and authenticates with a device ID, then lists tournaments and updates the UI. Also handles joining tournaments, submitting scores, deleting the player's record, and record pagination.

**Authentication**

```csharp
// Connect to Nakama and authenticate with device ID
await AuthenticateWithDevice();
```

API reference: [Authentication](../../../nakama/client-libraries/unity/#authentication)

**Tournament operations**

```csharp
// List active tournaments
var list = await Client.ListTournamentsAsync(session, tournamentID, ownerIds, expiry, limit, cursor);

// Join the selected tournament
await Client.JoinTournamentAsync(session, tournamentId);

// Submit a score (with operator and optional subscore)
await Client.WriteTournamentRecordAsync(
    session, tournamentId, score, subscore, metadata, operator);

// Delete the player's record
await Client.DeleteTournamentRecordAsync(session, tournamentId);
```

API reference: [Tournaments](../../../nakama/client-libraries/unity/#tournaments)

**Record browsing**

```csharp
// Fetch records for the selected tournament (includes the current player's record)
var page = await Client.ListTournamentRecordsAsync(
    session, tournamentId, ownerIds, expiry, limit, cursor);
```

The controller pins the owner's record separately, shows the per-user submission limit (`current/max`), and disables the submit button when the limit is reached. It also toggles between "joined" and "not joined" controls depending on whether the tournament is joinable.

#### Tournament view (`TournamentView.cs`)

Displays each tournament's title, current size vs. max size, and a time-remaining readout based on `NextReset`.

#### Record view (`TournamentRecordView.cs`)

Displays the player's rank, username, score, and sub-score.
