# Get started with LevelPlay components

> Add the LevelPlay SDK and a rewarded ad to your game from the Unity Editor, and configure privacy settings before the SDK initializes.

LevelPlay components let you add the LevelPlay SDK and banner, interstitial, and rewarded ads to your game from the Unity Editor, without writing integration code. This page shows you how to add a rewarded ad and grant its reward. To add a banner or interstitial ad, follow the same steps and select that component's menu item instead.

Some APIs must be called before the SDK initializes. If your game uses privacy settings, test suite metadata, or the global impression data subscription, refer to [Configure privacy, test suite, and impression data before initialization](#configure-privacy-test-suite-and-impression-data-before-initialization).

For more information on how the components work, refer to [Introduction to LevelPlay components](/grow/levelplay/sdk/unity/intro-to-levelplay-components.md).

## Prerequisites

Before you begin, make sure you meet the following requirements:

* The Ads Mediation package (`com.unity.services.levelplay`) is installed in your project. For more information, refer to [Unity Package integration](/grow/levelplay/sdk/unity/package-integration.md).
* An app is set up in the LevelPlay dashboard, and you have its **App Key** for each platform you target (Android, iOS, or both).
* An ad unit is created in the LevelPlay dashboard for each ad format you want to show, and you have its **Ad Unit ID** for each platform.

## Add a rewarded ad to your game

To add the LevelPlay SDK and a rewarded ad to your game, do the following:

1. Open the scene where your game starts, for example your boot or main menu scene.
2. Select **GameObject** > **Monetization** > **LevelPlay SDK**. This creates a `GameObject` named `LevelPlay`.
3. In the **Inspector** window, enter your **Android App Key**, **iOS App Key**, or both.
4. Select **GameObject** > **Monetization** > **Rewarded Ad (LevelPlay)**. To add a different ad format, select **Banner Ad (LevelPlay)** or **Interstitial Ad (LevelPlay)** instead.
5. In the **Inspector** window, enter the **Android Ad Unit ID**, **iOS Ad Unit ID**, or both.
6. Connect the ad to your game:
   * To show the ad, select a UI Button and add an entry to its **On Click ()** list. Drag the **Rewarded Ad (LevelPlay)** `GameObject` into the object field and select **LevelPlayRewardedAdBehaviour** > **ShowAd ()**.
   * To grant the reward, add an entry to the **On Ad Rewarded** event on the **Rewarded Ad (LevelPlay)** component, and select the method on your `GameObject` that grants the reward. For an example, refer to [Grant a reward with a script](#grant-a-reward-with-a-script).
7. Enter Play mode.

When you enter Play mode, the SDK initializes, the ad loads automatically, and selecting the button shows the ad. In the Unity Editor, LevelPlay simulates initialization and shows mock ads, so you can test your event connections without a device. In Play mode, each component's **Inspector** window shows a **Play Mode Controls** section.

For the properties of each ad component, refer to the [**Banner Ad (LevelPlay)**](/grow/levelplay/sdk/unity/component-reference.md#banner-ad-\(levelplay\)-component-properties), [**Interstitial Ad (LevelPlay)**](/grow/levelplay/sdk/unity/component-reference.md#interstitial-ad-\(levelplay\)-component-properties), and [**Rewarded Ad (LevelPlay)**](/grow/levelplay/sdk/unity/component-reference.md#rewarded-ad-\(levelplay\)-component-properties) sections of [LevelPlay component reference](/grow/levelplay/sdk/unity/component-reference.md).

For the public methods and events of each component, refer to the [**Banner Ad (LevelPlay)** component API](/grow/levelplay/sdk/unity/component-api-reference.md#banner-ad-\(levelplay\)-component-class), [**Interstitial Ad (LevelPlay)** component API](/grow/levelplay/sdk/unity/component-api-reference.md#interstitial-ad-\(levelplay\)-component-class), and [**Rewarded Ad (LevelPlay)** component API](/grow/levelplay/sdk/unity/component-api-reference.md#rewarded-ad-\(levelplay\)-component-class).

> **Note:**
>
> If you create an ad `GameObject` and the scene doesn't have a LevelPlay SDK `GameObject` yet, Unity creates one for you. A scene can contain only one LevelPlay SDK `GameObject`. If one already exists, selecting the **LevelPlay SDK** menu item selects it instead of creating a second one.

If the **Console** window shows an error message, refer to [Troubleshoot ad initialization and display](/grow/levelplay/sdk/unity/troubleshoot-component-display.md).

## Grant a reward with a script

Create a script that grants the reward. The following example adds the reward amount to `Coins`:

```csharp
using Unity.Services.LevelPlay;
using UnityEngine;

public class CoinWallet : MonoBehaviour
{
    public int Coins;

    public void GrantReward(LevelPlayAdInfo adInfo, LevelPlayReward reward)
    {
        Coins += reward.Amount;
    }
}
```

To connect the script to the reward, do the following:

1. On the **Rewarded Ad (LevelPlay)** component, add an entry to **On Ad Rewarded**.
2. Drag in the `GameObject` that has the `CoinWallet` component.
3. Select **CoinWallet** > **GrantReward** from the **Dynamic** section of the list.

> **Important:**
>
> Grant the reward in **On Ad Rewarded**. Don't grant it in **On Ad Closed**.

## Configure privacy, test suite, and impression data before initialization

The following APIs must be called before the SDK initializes:

* Privacy settings (`LevelPlayPrivacySettings`)
* Test suite metadata (`LevelPlay.SetMetaData("is_test_suite", "enable")`)
* The global `LevelPlay.OnImpressionDataReady` subscription

To make sure these APIs run before the SDK initializes, use one of the following options:

* [Call the APIs before the SDK starts](#call-the-apis-before-the-sdk-starts): Keep **Initialize On Start** enabled and call the APIs from `Awake()` in a script in the same scene.
* [Initialize the SDK](#initialize-the-sdk): Disable **Initialize On Start**, call the APIs, and then call [`Initialize()`](/grow/levelplay/sdk/unity/component-api-reference.md#levelplay-sdk-component-class) yourself.

### Call the APIs before the SDK starts

Unity runs `Awake()` on every object before it runs the SDK component's `Start()`.

To call the APIs before the SDK initializes, do the following:

1. Keep **Initialize On Start** enabled.
2. Call the APIs from `Awake()` in one of your scripts in the same scene.

The following example sets GDPR and CCPA consent in `Awake()`:

```csharp
using Unity.Services.LevelPlay;
using UnityEngine;

public class AdsPrivacySetup : MonoBehaviour
{
    void Awake()
    {
        // Pass the consent choices the player recorded in your consent dialog.
        LevelPlayPrivacySettings.SetGDPRConsent(true);
        LevelPlayPrivacySettings.SetCCPA(false);
    }
}
```

For more information about privacy settings, refer to [Regulation advanced settings for Unity](/grow/levelplay/sdk/unity/regulation-advanced-settings.md).

### Initialize the SDK

To initialize the SDK manually, do the following:

1. On the **LevelPlay SDK** component, disable **Initialize On Start**.
2. Call `Initialize()` on the component when you're ready, for example after the player answers your consent dialog. You can call it from a `UnityEvent`, such as a button's **On Click ()**, or from code.

## Next steps

To control when ads show, refer to [Show and hide ads during gameplay](/grow/levelplay/sdk/unity/manage-components.md).
