# Unity でのインタースティシャル広告の実装

> Unity プロジェクトにインタースティシャル広告を実装します。ゲームのモーメントまたはアプリケーション遷移の間に、C# スクリプトを使用して広告コンテンツをロードし、表示します。

`Advertisements API` を使用して全画面のインタースティシャル広告を表示するには、SDK を初期化した後に、`Load` 関数を使用して広告コンテンツをプレースメントにロードし、`Show` 関数を使用して広告を表示します。

> **Note:**
>
> 2026 年 4 月 1 日より、Advertisement Legacy パッケージを介した直接インテグレーションによって Unity Ads で収益化するアプリケーションでは、広告のパフォーマンスが低下する可能性があります。パフォーマンスの削減を回避するには、Unity Adsを入札者として統合する方式に切り替えます。
>
> Unity Ads ネットワークは、直接インテグレーションを使用するすべてのアプリケーションのサポートと提供を継続します。ただし、収益とパフォーマンスを最大化するために推奨されるベストプラクティスは、Unityの広告メディエーションプラットフォームであるLevelPlay用のAds Mediationパッケージ[をインストールする](/grow/levelplay/sdk/unity/package-integration.md.md)ことです。

SDK バージョン 3.7.0 以降では、`IUnityAdsLoadListener` コールバックと `IUnityAdsShowListener` コールバックを使用して、それぞれコンテンツのロードまたは表示が成功または失敗したときのためのロジックを実装できます。

> **Note:**
>
> `Show` メソッドを呼び出すときは、プレースメント ID を指定する必要があります。指定しない場合、エラーが発生します。

## インタースティシャル広告の例##interstitial-ad-example

1. **C#**

   ```cs
   using UnityEngine;
   using UnityEngine.Advertisements;

   public class InterstitialAdExample : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
   {
     [SerializeField] string _androidAdUnitId = "Interstitial_Android";
     [SerializeField] string _iOSAdUnitId = "Interstitial_iOS";
     string _adUnitId;

     void Awake()
     {
       // Get the Ad Unit ID for the current platform:
       _adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
       ? _iOSAdUnitId
       : _androidAdUnitId;
     }

     // Load content to the Ad Unit:
     public void LoadAd()
     {
       // IMPORTANT!コンテンツのロードは初期化した後にのみ行ってください (この例では、初期化は別のスクリプトで処理されています)。
       Debug.Log("Loading Ad: " + _adUnitId);
       Advertisement.Load(_adUnitId, this);
     }

     // Show the loaded content in the Ad Unit:
     public void ShowAd()
     {
       // Note that if the ad content wasn't previously loaded, this method will fail
       Debug.Log("Showing Ad: " + _adUnitId);
       Advertisement.Show(_adUnitId, this);
     }

     // Implement Load Listener and Show Listener interface methods:
     public void OnUnityAdsAdLoaded(string adUnitId)
     {
       // Optionally execute code if the Ad Unit successfully loads content.
     }

     public void OnUnityAdsFailedToLoad(string _adUnitId, UnityAdsLoadError error, string message)
     {
       Debug.Log($"Error loading Ad Unit: {_adUnitId} - {error.ToString()} - {message}");
       // Optionally execute code if the Ad Unit fails to load, such as attempting to try again.
     }

     public void OnUnityAdsShowFailure(string _adUnitId, UnityAdsShowError error, string message)
     {
       Debug.Log($"Error showing Ad Unit {_adUnitId}: {error.ToString()} - {message}");
       // Optionally execute code if the Ad Unit fails to show, such as loading another ad.
     }

     public void OnUnityAdsShowStart(string _adUnitId) { }
     public void OnUnityAdsShowClick(string _adUnitId) { }
     public void OnUnityAdsShowComplete(string _adUnitId, UnityAdsShowCompletionState showCompletionState) { }
   }
   ```

**次のステップ**: 実装を改善するには、[Unity でのリワード広告の実装](/ads-unity/4.19.0/sdk-integration/rewarded-ads.md) に関するドキュメントを参照してください。
