# 4-4. Interstitial Video Ads for Unity (Non Reward)

## Before you begin

{% content-ref url="/pages/E4sVveRS1O07LDkxrZrf" %}
[04. Unity-Plugin Guide](/one-admax-sdk/oneadmax_dev_guide_en/unityplugin.md)
{% endcontent-ref %}

## ONEAdMax SDK initialize

Initialization of **ONEAdMax** is required before loading ads.\
\&#xNAN;**`ONEAdMaxClient.Initialize()`** should only be executed once during the initial setup.

```csharp
...
using ONEAdMax;
...
public class ONEAdMaxDemo : MonoBehaviour
{
    private static bool _isInitialized = false;
    
    void Start()
    {
        if (!_isInitialized)
        {
            // Initialize the ONEAdMax SDK.
            ONEAdMaxClient.Initialize(() =>
            {
                // This callback is called once the ONEAdMax SDK is initialized.
                _isInitialized = true
            });
        }
    }
}
```

## **Interstitial Video Ads sample code**

You can create an instance of **OAMInterstitialVideo** and handle events to extend its functionality.

### Create an instance of the **OAMInterstitialVideo** ad.

{% code fullWidth="false" %}

```csharp
public class InterstitialVideoAdController : MonoBehaviour
{
    OAMInterstitialVideo _interstitialVideoAd;
    
    /// <summary>
    /// Creates the ad.
    /// </summary>
    public void CreateInterstitialVideoAd()
    {
        Debug.Log("Creating Interstitial video ad.");
        
        if (_interstitialVideoAd != null)
        {
            Debug.LogWarning("Already have a Interstitial video ad.");
            return;
        }

        _interstitialVideoAd = new OAMInterstitialVideo();
    }
}
```

{% endcode %}

### Set the network schedule timeout (optional)

광고에 대한 네트워크 스케쥴 타임아웃을 설정합니다. (기본값: 5초) \
광고 로딩 시 각 네트워크 별로 타임아웃 시간을 주어 해당 시간 안에 광고를 받지 못할 경우, 다음 네트워크로 넘어갑니다.

```csharp
_interstitialVideoAd.SetNetworkScheduleTimeout(5); // Default 5 seconds
```

### Set the event listener for **Interstitial Video Ads** (optional)

```csharp
/// <summary>
/// Register to events the interstital video ad may raise.
/// </summary>
private void RegisterEvents(OAMInterstitialVideo ad)
{
    // Raised when an ad is loaded into the interstitial ad.
    ad.OnLoaded += () =>
    {
        Debug.Log("Interstitial video ad loaded.");
    };

    // Raised when an ad fails to load into the interstitial ad.
    ad.OnLoadFailed += (OAMError error) =>
    {
        Debug.LogError("Interstitial video ad failed to load an ad with error : " + error);
    };

    // Raised when an ad opened full screen content.
    ad.OnOpened += () =>
    {
        Debug.Log("Interstitial video ad has been opened.");
    };

    // Raised when the ad failed to open full screen content.
    ad.OnOpenFailed += (OAMError error) =>
    {
        Debug.LogError("Interstitial video ad failed to open an ad with error : " + error);
    };

    // Raised when the ad closed full screen content.
    ad.OnClosed += () =>
    {
        Debug.LogError("Interstitial video ad is closed.");
    };
}
```

{% content-ref url="/pages/i8O1iX5eJtrY4LjZBdFC" %}
[ONE AdMax SDK Error Codes](/one-admax-sdk/oneadmax_dev_guide_en/oamerror.md)
{% endcontent-ref %}

## Create an instance of the **Interstitial Video Ad**

Complete all the settings and create the **OAMInterstitialVideo**.

```csharp
// These ad units are configured to always serve test ads.   
private readonly string _placementId = "string your placementID";

_interstitialVideoAd.Create(_placementId);
```

## Load the **Interstitial Video Ad**.

전면 비디오 광고 `Load()` API를 호출하여 서버에 광고를 요청합니다.

```csharp
/// <summary>
/// Loads the ad.
/// </summary>
public void Load()
{
    if (_interstitialVideoAd == null)
    {
        Debug.LogWarning("The interstital video ad is null.");
        return;
    }

    _interstitialVideoAd.Load();
}
```

{% hint style="warning" %}
Excessive ad requests can lead to blocking, so please be cautious!
{% endhint %}

## Display the **Interstitial Video Ad**.

로드가 완료되면 광고를 노출을 원하는 시점에 `Show()` API를 호출하여 화면에 노출 시킵니다.

```csharp
/// <summary>
/// Shows the ad.
/// </summary>
public void Show()
{
    if (_interstitialVideoAd != null && _interstitialVideoAd.IsLoaded())
    {
        Debug.Log("Showing interstital video ad.");
        _interstitialVideoAd.Show();
    }
    else
    {
        Debug.LogError("The Interstitial video ad hasn't loaded yet.");
    }
}
```

## Destroy the memory for the **Interstitial Video Ad**.

```csharp
/// <summary>
/// Destroys the ad.
/// </summary>
public void Destroy()
{
    if (_interstitialVideoAd != null)
    {
        Debug.Log("Destroying interstitial video ad.");
        _interstitialVideoAd.Destroy();
        _interstitialVideoAd = null;
    }
}
```

## Check whether the **Interstitial Video Ad** is loaded

Check whether the **Interstitial Video Ad** is loaded. (returns **true** | **false**)

```csharp
_interstitialVideoAd.IsLoaded();
```


---

# 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://one-admax-organization.gitbook.io/one-admax-sdk/oneadmax_dev_guide_en/unityplugin/video.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.
