# LevelPlay component API reference

> Use the public methods and events of the LevelPlay components to control ads from your scripts.

This page documents the public methods, properties, and events of the four LevelPlay component classes:

* [LevelPlay SDK component class](#levelplay-sdk-component-class)
* [Banner Ad (LevelPlay) component class](#banner-ad-\(levelplay\)-component-class)
* [Interstitial Ad (LevelPlay) component class](#interstitial-ad-\(levelplay\)-component-class)
* [Rewarded Ad (LevelPlay) component class](#rewarded-ad-\(levelplay\)-component-class)

For the **Inspector** window properties of each component, refer to [LevelPlay component reference](/grow/levelplay/sdk/unity/component-reference.md).

## LevelPlay SDK component class

The `LevelPlaySdkBehaviour` class initializes the LevelPlay SDK. Add it once, in the first scene your game loads.

Related API: [`LevelPlay.Init`](/grow/levelplay/sdk/unity/package-integration.md#initialize-the-sdk)

### Methods

| Method                     | Description                                                                                                                                         |
| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Initialize()`             | Initializes the SDK with the app key for the current platform and the configured user ID. If no app key is set, it logs a warning and does nothing. |
| `SetPauseGame(bool pause)` | Same as `LevelPlay.SetPauseGame`. This method is supported only on iOS.                                                                             |

### Events

| Event               | Description                                                                      | Parameters               |
| ------------------- | -------------------------------------------------------------------------------- | ------------------------ |
| **On Init Success** | Invoked when the SDK initializes successfully. Invoked on the Unity main thread. | `LevelPlayConfiguration` |
| **On Init Failed**  | Invoked when the SDK fails to initialize. Invoked on the Unity main thread.      | `LevelPlayInitError`     |

## Banner Ad (LevelPlay) component class

The `LevelPlayBannerAdBehaviour` class loads and displays a banner ad at a fixed position on the screen.

Related API: `LevelPlayBannerAd`

> **Important:**
>
> The banner reads its **Inspector** properties when it creates the ad, on its first load. To apply changes later, call `DestroyAd()` and then `LoadAd()`.

### Methods and properties

| Member                                                                             | Description                                                                         |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `LoadAd()`                                                                         | Creates the banner from the **Inspector** settings on the first call, and loads it. |
| `ShowAd()`                                                                         | Shows the banner. Does nothing before the banner is created.                        |
| `HideAd()`                                                                         | Hides the banner without destroying it.                                             |
| `DestroyAd()`                                                                      | Destroys the banner. The next `LoadAd()` call creates a new one.                    |
| `PauseAutoRefresh()`, `ResumeAutoRefresh()`                                        | Pauses or resumes the banner's auto-refresh.                                        |
| `GetAdId()`, `GetAdUnitId()`, `GetAdSize()`, `GetPosition()`, `GetPlacementName()` | Returns the banner's current values.                                                |
| `Ad`                                                                               | The underlying `LevelPlayBannerAd`, or `null` if no ad exists.                      |

### Events

| Event                           | Description                                                                                                | Parameters                            |
| ------------------------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------- |
| **On Ad Loaded**                | Invoked when the banner loads.                                                                             | `LevelPlayAdInfo`                     |
| **On Ad Load Failed**           | Invoked when the banner fails to load.                                                                     | `LevelPlayAdError`                    |
| **On Ad Displayed**             | Invoked when the banner becomes visible.                                                                   | `LevelPlayAdInfo`                     |
| **On Ad Display Failed**        | Invoked when the banner fails to display.                                                                  | `LevelPlayAdInfo`, `LevelPlayAdError` |
| **On Ad Clicked**               | Invoked when the player clicks the banner.                                                                 | `LevelPlayAdInfo`                     |
| **On Ad Expanded**              | Invoked when the banner expands to cover the screen.                                                       | `LevelPlayAdInfo`                     |
| **On Ad Collapsed**             | Invoked when the banner returns from its expanded state.                                                   | `LevelPlayAdInfo`                     |
| **On Ad Left Application**      | Invoked when the app goes to the background after the player clicks the banner.                            | `LevelPlayAdInfo`                     |
| **On Ad Impression Data Ready** | Invoked when impression-level revenue data is available for this banner. Invoked on the Unity main thread. | `LevelPlayImpressionData`             |

## Interstitial Ad (LevelPlay) component class

The `LevelPlayInterstitialAdBehaviour` class loads and shows a full-screen interstitial ad, for example between levels. It exposes its settings as public properties, such as `AndroidAdUnitId`, `LoadOnStart`, and `PlacementName`, and its events as public `UnityEvent` properties.

Related API: `LevelPlayInterstitialAd`

For an example that uses this class, refer to [Show an interstitial ad from a script](/grow/levelplay/sdk/unity/manage-components.md#show-an-interstitial-ad-from-a-script).

### Methods and properties

| Member                                                           | Description                                                                                   |
| ---------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `LoadAd()`                                                       | Creates the ad from the **Inspector** settings on the first call, and loads it.               |
| `ShowAd()`                                                       | Shows the ad using **Placement Name**. If no ad is ready, it logs a warning and does nothing. |
| `ShowAd(string placementName)`                                   | Shows the ad with a specific placement.                                                       |
| `IsAdReady()`                                                    | Returns `true` if an ad is loaded and ready to show.                                          |
| `IsPlacementCapped()`, `IsPlacementCapped(string placementName)` | Returns `true` if the placement is capped.                                                    |
| `DestroyAd()`                                                    | Destroys the ad. The next `LoadAd()` call creates a new one.                                  |
| `GetAdId()`                                                      | Returns the ID of the current ad, or `null`.                                                  |
| `Ad`                                                             | The underlying `LevelPlayInterstitialAd`, or `null`.                                          |

### Events

| Event                           | Description                                                                                | Parameters                            |
| ------------------------------- | ------------------------------------------------------------------------------------------ | ------------------------------------- |
| **On Ad Loaded**                | Invoked when the ad loads and is ready to show.                                            | `LevelPlayAdInfo`                     |
| **On Ad Load Failed**           | Invoked when the ad fails to load.                                                         | `LevelPlayAdError`                    |
| **On Ad Displayed**             | Invoked when the ad opens.                                                                 | `LevelPlayAdInfo`                     |
| **On Ad Display Failed**        | Invoked when the ad fails to show.                                                         | `LevelPlayAdInfo`, `LevelPlayAdError` |
| **On Ad Clicked**               | Invoked when the player clicks the ad.                                                     | `LevelPlayAdInfo`                     |
| **On Ad Closed** (`OnAdClosed`) | Invoked when the player closes the ad. Resume your game here.                              | `LevelPlayAdInfo`                     |
| **On Ad Info Changed**          | Invoked when the ad info of a loaded ad changes.                                           | `LevelPlayAdInfo`                     |
| **On Ad Impression Data Ready** | Invoked when impression-level revenue data is available. Invoked on the Unity main thread. | `LevelPlayImpressionData`             |

## Rewarded Ad (LevelPlay) component class

The `LevelPlayRewardedAdBehaviour` class loads and shows a full-screen rewarded ad that grants the player a reward when they finish watching it.

Related API: `LevelPlayRewardedAd`

For an example of a method that you connect to **On Ad Rewarded** in the **Inspector** window, refer to [Grant a reward with a script](/grow/levelplay/sdk/unity/get-started-components.md#grant-a-reward-with-a-script).

The `LevelPlayRewardedAdBehaviour` class has all the methods, properties, and events of the [`LevelPlayInterstitialAdBehaviour` class](#interstitial-ad-\(levelplay\)-component-class), plus the following methods and event.

### Methods

| Method                        | Description                                                                                          | Parameters                                        | Returns                                                                                                                           |
| ----------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `GetReward()`                 | Gets the reward for **Placement Name**. Use it for pre-show UI, such as "Watch an ad for 100 coins". | None                                              | The reward set for **Placement Name**, or the ad unit's default reward when no placement is set. `null` before the ad is created. |
| `GetReward(string placement)` | Gets the reward for a specific placement.                                                            | `placement`: The placement to get the reward for. | The reward for the placement.                                                                                                     |

### Events

| Event              | Description                                                                                          | Parameters                           |
| ------------------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------ |
| **On Ad Rewarded** | Invoked when the player earns the reward. Grant the reward here. Don't grant it in **On Ad Closed**. | `LevelPlayAdInfo`, `LevelPlayReward` |
