# Unity Example

We have created a public [repository](https://github.com/triumpharcade/triumph-kit-unity-demo) that contains a demo integration of the Triumph SDK in a template game.

If you wish to run this demo, be sure to include the following scenes in your build:

![](/files/7v3pWuPmXHCoVOJYrov5)

The `Triumph` methods are called in `MainMenuUIManager` and `GameUIManager`, with the code that would go in their place contained in a block comment to their left:

```csharp
using TriumphSDK;

public class MainMenuUIManager : MonoBehaviour
{
    [SerializeField] Button startGameButton;

    void Start()
    {
        // instead of starting the game, the button will now launch the Triumph SDK
        startGameButton.onClick.AddListener(() => /* StartGame() */ Triumph.PresentTriumphViewController());
    }

    // to run the integration, the logic for this method should be moved to TriumphUnityNativeMethods.TriumphGameDidStart()
    private void StartGame()
    {
        SceneManager.LoadScene("Game");
    }
}
```

```csharp
using TriumphSDK;

public class GameUIManager : MonoBehaviour
{
    [SerializeField] TMP_Text scoreText;
    [SerializeField] TMP_Text secondaryText;

    [SerializeField] Button updateScoreButton;
    [SerializeField] Button reportScoreButton;

    void Start()
    {
        PlayerPrefs.SetFloat("Score", 0f);

        updateScoreButton.onClick.AddListener(() => UpdateScore());
        reportScoreButton.onClick.AddListener(() => ReportRandomScore());
    }

    private void Update()
    {
        // the two labels should be updated using the strings provided by Triumph
        scoreText.text = /* PlayerPrefs.GetFloat("Score") */ Triumph.GetTriumphPrimaryLabel();
        secondaryText.text = /* "I am the smaller text" */ Triumph.GetTriumphSecondaryLabel();
    }

    private void UpdateScore()
    {
        // all instances of randomness (i.e. Random.Range()) should be replaced with TriumphSDK.GetRandom()
        PlayerPrefs.SetFloat("Score", PlayerPrefs.GetFloat("Score", 0f) + /* Random.Range(0f, 10f) */ Triumph.GetRandom(0f, 10f));

        // whenever the score is updated, be sure to notify the Triumph SDK of the change
        Triumph.UpdateScore(PlayerPrefs.GetFloat("Score"));
    }

    private void ReportRandomScore()
    {
        SceneManager.LoadScene("GameOver");

        // show the Triumph SDK when the game ends
        Triumph.PresentTriumphGameOver(PlayerPrefs.GetFloat("Score"));
    }
}
```

Note that when playing the game, you are presented with two buttons, one labeled "Update Score" and one labeled "Report Score". The former increases the score by a random amount, and the latter completes the current game and reports the final score to the Triumph SDK, which will open the Triumph window.

![](/files/jNQFB9wNe9Icgo53bE85)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.triumpharcade.com/triumph-sdk/demo-integrations/unity-example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
