usingGoogleMobileAds;usingGoogleMobileAds.Api;publicclassGoogleMobileAdsDemoScript:MonoBehaviour{publicvoidStart(){// Initialize the Google Mobile Ads SDK.MobileAds.Initialize((InitializationStatusinitStatus)=>
{// This callback is called once the MobileAds SDK is initialized.});}}
// Create our request used to load the ad.varadRequest=newAdRequest();// Send the request to load the ad.InterstitialAd.Load("AD_UNIT_ID",adRequest,(InterstitialAdad,LoadAdErrorerror)=>
{if(error!=null){// The ad failed to load.return;}// The ad loaded successfully.});
interstitialAd.OnAdFullScreenContentClosed+=()=>
{// Reload the ad so that we can show another as soon as possible.varadRequest=newAdRequest();InterstitialAd.Load("AD_UNIT_ID",adRequest,(InterstitialAdad,LoadAdErrorerror)=>
{// Handle ad loading here.});};
[null,null,["最后更新时间 (UTC):2025-08-26。"],[[["\u003cp\u003eInterstitial ads are full-screen ads displayed at natural transition points in an app, allowing users to interact or close them.\u003c/p\u003e\n"],["\u003cp\u003eThis guide provides instructions on integrating interstitial ads into a Unity app, covering initialization, loading, displaying, and event handling.\u003c/p\u003e\n"],["\u003cp\u003eBefore displaying interstitial ads in your app, ensure the Mobile Ads SDK is initialized using \u003ccode\u003eMobileAds.Initialize()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo show an interstitial ad, call the \u003ccode\u003eShow()\u003c/code\u003e method on the \u003ccode\u003eInterstitialAd\u003c/code\u003e instance, but first verify its readiness using \u003ccode\u003eCanShowAd()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eBest practices include strategically placing ads at transition points, pausing app activity while ads are displayed, and avoiding excessive ad frequency to maintain a positive user experience.\u003c/p\u003e\n"]]],["Interstitial ads, displayed full-screen at natural app transitions, require integration with the Mobile Ads SDK. Key actions include: initializing the SDK, loading an ad using `InterstitialAd.Load()` with an ad unit ID and `AdRequest`, and showing it with `Show()`. Listen for events like `OnAdFullScreenContentClosed` to preload new ads. Always destroy ads with `Destroy()` after use. Test ads first using provided IDs and set up test devices. Ensure ads don't disrupt user experience, and pause app resources while they are displayed.\n"],null,["# Interstitial ads\n\nSelect platform: [Android](/admob/android/interstitial \"View this page for the Android platform docs.\") [iOS](/admob/ios/interstitial \"View this page for the iOS platform docs.\") [Unity](/admob/unity/interstitial \"View this page for the Unity platform docs.\") [Flutter](/admob/flutter/interstitial \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nInterstitial ads are full-screen ads that cover the interface of their host app.\nThey're typically displayed at natural transition points in the flow of an app,\nsuch as during the pause between levels in a game. When an app shows an\ninterstitial ad, the user has the choice to either tap on the ad and continue to\nits destination or close it and return to the app.\n\n[Case study](//admob.google.com/home/resources/freaking-math-powers-revenue-increase-with-google-admob-support/).\n\n\nThis guide explains how to integrate interstitial ads into a Unity app.\n\nPrerequisites\n-------------\n\n- Complete the [Get started guide](/admob/unity/quick-start).\n\nAlways test with test ads\n-------------------------\n\nThe following sample code contains an ad unit ID which you can use to request\ntest ads. It's been specially configured to return test ads rather than\nproduction ads for every request, making it safe to use.\n\nHowever, after you've registered an app in the\nAdMob web interface and created your own ad unit\nIDs for use in your app, explicitly [configure your device as a test\ndevice](/admob/unity/test-ads#enable_test_devices) during\ndevelopment. \n\n### Android\n\n`ca-app-pub-3940256099942544/1033173712`\n\n### iOS\n\n`ca-app-pub-3940256099942544/4411468910`\n\nInitialize the Mobile Ads SDK\n-----------------------------\n\nBefore loading ads, have your app initialize the Mobile Ads SDK by calling\n`MobileAds.Initialize()`. This needs to be done only once, ideally at app launch. \n\n using GoogleMobileAds;\n using GoogleMobileAds.Api;\n\n public class GoogleMobileAdsDemoScript : MonoBehaviour\n {\n public void Start()\n {\n // Initialize the Google Mobile Ads SDK.\n MobileAds.Initialize((InitializationStatus initStatus) =\u003e\n {\n // This callback is called once the MobileAds SDK is initialized.\n });\n }\n }\n\nIf you're using mediation, wait until the callback occurs before loading ads as\nthis will ensure that all mediation adapters are initialized.\n\nLoad the interstitial ad\n------------------------\n\nLoading an interstitial ad is accomplished using the static `Load()` method on the\n`InterstitialAd` class. The load method requires an ad unit ID, an\n`AdRequest` object, and a completion handler which\ngets called when ad loading succeeds or fails. The loaded\n`InterstitialAd` object is provided as a parameter in\nthe completion handler. The following example loads InterstitialAd: \n\n // Create our request used to load the ad.\n var adRequest = new AdRequest();\n\n // Send the request to load the ad.\n InterstitialAd.Load(\"\u003cvar translate=\"no\"\u003eAD_UNIT_ID\u003c/var\u003e\", adRequest, (InterstitialAd ad, LoadAdError error) =\u003e\n {\n if (error != null)\n {\n // The ad failed to load.\n return;\n }\n // The ad loaded successfully.\n }); \n https://github.com/googleads/googleads-mobile-unity/blob/2de30b494685db5152d07b44ab01e833ca8f20f7/samples/HelloWorld/Assets/Snippets/InterstitialAdSnippets.cs#L21-L33\n\nReplace \u003cvar class=\"readonly\" translate=\"no\"\u003eAD_UNIT_ID\u003c/var\u003e with your ad unit ID.\n| **Warning:** Attempting to load a new ad from the ad request completion block when an ad failed to load is strongly discouraged. If you must load an ad from the ad request completion block, limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity.\n\n\n| **Tip:** You can use ad load calls to build up a cache of preloaded ads before you intend to show them, so that ads can be shown with zero latency when needed. Since ads expire after an hour, you should clear this cache and reload with new ads every hour.\n\n\u003cbr /\u003e\n\nShow the interstitial ad\n------------------------\n\nTo show a loaded interstitial ad, call the `Show()` method on the\n`InterstitialAd` instance. Ads may be shown once per\nload. Use the `CanShowAd()` method to verify that the ad is ready to be shown.\n**Note:** Interstitial ads should be displayed during natural pauses in the flow of an app, such as between levels of a game or after the user completes a task. \n\n if (interstitialAd != null && interstitialAd.CanShowAd())\n {\n interstitialAd.Show();\n } \n https://github.com/googleads/googleads-mobile-unity/blob/2de30b494685db5152d07b44ab01e833ca8f20f7/samples/HelloWorld/Assets/Snippets/InterstitialAdSnippets.cs#L40-L43\n\nListen to interstitial ad events\n--------------------------------\n\nTo further customize the behavior of your ad, you can hook into a number of\nevents in the ad's lifecycle. The following example listens to ad events: \n\n interstitialAd.OnAdPaid += (AdValue adValue) =\u003e\n {\n // Raised when the ad is estimated to have earned money.\n };\n interstitialAd.OnAdImpressionRecorded += () =\u003e\n {\n // Raised when an impression is recorded for an ad.\n };\n interstitialAd.OnAdClicked += () =\u003e\n {\n // Raised when a click is recorded for an ad.\n };\n interstitialAd.OnAdFullScreenContentOpened += () =\u003e\n {\n // Raised when the ad opened full screen content.\n };\n interstitialAd.OnAdFullScreenContentClosed += () =\u003e\n {\n // Raised when the ad closed full screen content.\n };\n interstitialAd.OnAdFullScreenContentFailed += (AdError error) =\u003e\n {\n // Raised when the ad failed to open full screen content.\n }; \n https://github.com/googleads/googleads-mobile-unity/blob/2de30b494685db5152d07b44ab01e833ca8f20f7/samples/HelloWorld/Assets/Snippets/InterstitialAdSnippets.cs#L50-L73\n\nClean up the interstitial ad\n----------------------------\n\nWhen you are finished with an `InterstitialAd`, make\nsure to call the `Destroy()` method before dropping your reference to it: \n\n if (interstitialAd != null)\n {\n interstitialAd.Destroy();\n } \n https://github.com/googleads/googleads-mobile-unity/blob/2de30b494685db5152d07b44ab01e833ca8f20f7/samples/HelloWorld/Assets/Snippets/InterstitialAdSnippets.cs#L80-L83\n\nThis notifies the plugin that the object is no longer used and the memory it\noccupies can be reclaimed. Failure to call this method results in memory leaks.\n\nPreload the next interstitial ad\n--------------------------------\n\nInterstitial ads are a one-time-use object. This means once an interstitial ad\nis shown, the object can't be used again. To request another interstitial ad,\ncreate a new `InterstitialAd` object.\n\nTo prepare an interstitial ad for the next impression opportunity, preload the\ninterstitial ad once the `OnAdFullScreenContentClosed` or\n`OnAdFullScreenContentFailed` ad event is raised. \n\n interstitialAd.OnAdFullScreenContentClosed += () =\u003e\n {\n // Reload the ad so that we can show another as soon as possible.\n var adRequest = new AdRequest();\n InterstitialAd.Load(\"\u003cvar translate=\"no\"\u003eAD_UNIT_ID\u003c/var\u003e\", adRequest, (InterstitialAd ad, LoadAdError error) =\u003e\n {\n // Handle ad loading here.\n });\n }; \n https://github.com/googleads/googleads-mobile-unity/blob/2de30b494685db5152d07b44ab01e833ca8f20f7/samples/HelloWorld/Assets/Snippets/InterstitialAdSnippets.cs#L90-L98\n\nBest practices\n--------------\n\nDetermine whether interstitial ads are the right type of ad for your app.\n: Interstitial ads work best in apps with natural transition points.\n The conclusion of a task within an app, such as sharing an image or completing a\n game level, creates such a point. Make sure you consider at which points in your\n app's flow to best display interstitial ads and how the user is likely to respond.\n\nPause the action when displaying an interstitial ad.\n: There are a number of different types of interstitial ads such as text,\n image, or video. It's important to make sure that when your app displays an\n interstitial ad, it also suspends its use of some resources to allow the ad to\n take advantage of them. For example, when you make the call to display an\n interstitial ad, be sure to pause any audio output being produced by your app.\n You can resume playing sounds in the `OnAdFullScreenContentClosed()` event,\n which can be invoked when the user has finished interacting with the ad. In\n addition, consider temporarily halting any intense computation tasks, such as a\n game loop, while the ad is being displayed. This ensures that the user doesn't\n experience slow or unresponsive graphics or stuttered video.\n\nDon't flood the user with ads.\n: While increasing the frequency of interstitial ads in your app might seem\n like a great way to increase revenue, it can also degrade the user experience\n and lower click-through rates. Make sure that users aren't so frequently\n interrupted that they're no longer able to enjoy the use of your app.\n\nAdditional resources\n--------------------\n\n- [HelloWorld example](//github.com/googleads/googleads-mobile-unity/tree/main/samples/HelloWorld): A minimal implementation of all ad formats.\n\n\\* [Sample use case](//admob.google.com/home/resources/freaking-math-powers-revenue-increase-with-google-admob-support/)"]]