Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 销毁广告(adMob)后如何将其带回?_Unity3d_Admob - Fatal编程技术网

Unity3d 销毁广告(adMob)后如何将其带回?

Unity3d 销毁广告(adMob)后如何将其带回?,unity3d,admob,Unity3d,Admob,这是我第一次实施广告。我正在使用adMob。我一直在乱搞不同的代码块,但我似乎无法创建一个新的广告,如果我破坏了它 private void RequestInterstitial() { // These ad units are configured to always serve test ads. #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId

这是我第一次实施广告。我正在使用adMob。我一直在乱搞不同的代码块,但我似乎无法创建一个新的广告,如果我破坏了它

private void RequestInterstitial()
{
    // These ad units are configured to always serve test ads.
    #if UNITY_EDITOR
    string adUnitId = "unused";
#elif UNITY_ANDROID
    string adUnitId = "ca-app-pub-3895731736666139/7005438200";
#elif UNITY_IPHONE
    string adUnitId = "hmm";
#else
    string adUnitId = "unexpected_platform";
#endif

    // Create an interstitial.
    this.interstitial = new InterstitialAd(adUnitId);

    // Register for ad events.
    this.interstitial.OnAdLoaded += this.HandleInterstitialLoaded;
    this.interstitial.OnAdFailedToLoad += this.HandleInterstitialFailedToLoad;
    this.interstitial.OnAdOpening += this.HandleInterstitialOpened;
    this.interstitial.OnAdClosed += this.HandleInterstitialClosed;
    this.interstitial.OnAdLeavingApplication += this.HandleInterstitialLeftApplication;

    // Load an interstitial ad.
    this.interstitial.LoadAd(this.CreateAdRequest());
}

private void ShowInterstitial()
{
    if (this.interstitial.IsLoaded())
    {
        this.interstitial.Show();
    }
    else
    {
        MonoBehaviour.print("Interstitial is not ready yet");
        text.text = "No Ad Loaded";
    }
}
现在要摧毁

this.interstitial.Destroy();
当您单击间隙上的“x”时,是否调用销毁函数

那我怎么把它带回来呢

当您单击屏幕上的“x”时,是否调用销毁函数 间隙的

。不太可能。如果这是真的,那么您必须执行
newinterstituralad(adUnitId)。单击x时,很可能是
interstitalad.Hide()被调用

我一直在处理不同的代码片段,但我不能 如果我把它毁了的话,它似乎在创造一个新的广告

private void RequestInterstitial()
{
    // These ad units are configured to always serve test ads.
    #if UNITY_EDITOR
    string adUnitId = "unused";
#elif UNITY_ANDROID
    string adUnitId = "ca-app-pub-3895731736666139/7005438200";
#elif UNITY_IPHONE
    string adUnitId = "hmm";
#else
    string adUnitId = "unexpected_platform";
#endif

    // Create an interstitial.
    this.interstitial = new InterstitialAd(adUnitId);

    // Register for ad events.
    this.interstitial.OnAdLoaded += this.HandleInterstitialLoaded;
    this.interstitial.OnAdFailedToLoad += this.HandleInterstitialFailedToLoad;
    this.interstitial.OnAdOpening += this.HandleInterstitialOpened;
    this.interstitial.OnAdClosed += this.HandleInterstitialClosed;
    this.interstitial.OnAdLeavingApplication += this.HandleInterstitialLeftApplication;

    // Load an interstitial ad.
    this.interstitial.LoadAd(this.CreateAdRequest());
}

private void ShowInterstitial()
{
    if (this.interstitial.IsLoaded())
    {
        this.interstitial.Show();
    }
    else
    {
        MonoBehaviour.print("Interstitial is not ready yet");
        text.text = "No Ad Loaded";
    }
}
那我怎么把它带回来呢

除非填隙声明超出范围,否则不应销毁它,然后应调用
interstival.destroy()

例如:

如果在函数中声明了interstival,则必须在该函数结束时销毁它,以避免内存泄漏

如果在函数/全局变量外部声明Interstival,则只应在Unity
OnDisable()
函数中销毁它。在您的情况下,它是一个全局变量,因此必须将
interstitual.Destroy()
放在
OnDisable()
函数中,这样当脚本销毁时,它也将销毁
interstitual

现在,如果你最终破坏了间质,你可以通过做
interstival=newinterstitalad(adUnitId)把它带回来interstival.LoadAd()
,然后调用
interstival.Show()
。在调用
interstitual.Show()
之前,必须先检查它是否已使用
if(interstitual.IsLoaded())
完成加载,然后再调用
interstitual.Show()


最后,当您注册一个事件时,您还应该在
OnDisable()
函数中取消注册该事件。您可以使用
+=
注册,也可以使用
-=
取消注册。因此,您应该使用
this.interstitual.OnAdLoaded-=this.handleinterstituialloadedinterstitial.Destroy()
函数之前,
OnDisable()
函数中的code>和其他事件也是如此。谢谢您的帮助!不客气。你可以从我的网站上得到我刚才提到的示例代码