首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我不能展示Interstitial广告?

为什么我不能展示Interstitial广告?
EN

Stack Overflow用户
提问于 2015-11-28 15:14:13
回答 1查看 172关注 0票数 1

我尝试过很多东西,但我无法在“团结”中播放间隙广告。我想显示间隙广告后,用户选择一个错误的答案,并在得分页面(“注意”现场)显示。这是我的代码,我只是复制了相关的部分:

代码语言:javascript
复制
 using UnityEngine;
 using UnityEngine.UI;
 using System.Text;
 using System.Xml;
 using System.Collections;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Xml.Serialization;
 using System.IO;
 using GoogleMobileAds;
 using GoogleMobileAds.Api;

 public class responder : MonoBehaviour
 {
     private InterstitialAd interstitial;

     private int gecis;

     public Text questionsorular;
     public Text responseA;
     public Text responseB;
     public Text responseC;
     public Text responseD;
     public Text infoResponses;
     public Text infoResponses1;
     public Text example;
     public Text dogrusayisi;

     private float corrects;
     private float questoesquestions;
     private float media;
     private int Notice;
 }

 void Start()
 {
     RequestInterstitial();
 }

 public void response(string alternative)
 {

     RequestInterstitial();

     if (alternative == "A")
     {
         if (responseA.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }

     else if (alternative == "B")
     {
         if (responseB.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }

     else if (alternative == "C")
     {
         if (responseC.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }

     else if (alternative == "D")
     {
         if (responseD.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }
 }

 void wrong()
 {
     ShowInterstitial();
     Application.LoadLevel("Notice");
 }

 private void RequestInterstitial()
 {
 #if UNITY_EDITOR
     string adUnitId = "unused";
 #elif UNITY_ANDROID
             string adUnitId = "MY ADS ID";
 #elif UNITY_IPHONE
             string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
 #else
             string adUnitId = "unexpected_platform";
 #endif

     // Create an interstitial.
     interstitial = new InterstitialAd(adUnitId);
     // Load an interstitial ad.
     interstitial.LoadAd(createAdRequest());
 }

 private AdRequest createAdRequest()
 {
     return new AdRequest.Builder()
             .AddTestDevice(AdRequest.TestDeviceSimulator)
             .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
             .AddKeyword("game")
             .SetGender(Gender.Male)
             .SetBirthday(new DateTime(1985, 1, 1))
             .TagForChildDirectedTreatment(false)
             .AddExtra("color_bg", "9B30FF")
             .Build();
 }

 private void ShowInterstitial()
 {
     if (interstitial.IsLoaded())
     {
         interstitial.Show();
     }
 }

当我将横幅广告附加到照相机上时,下面的代码非常适合它:

代码语言:javascript
复制
 using UnityEngine;
 using GoogleMobileAds.Api;

 public class Ads : MonoBehaviour
 {
     void Start()
     {
         BannerView adsObject = new BannerView(
                 "MY ADS ID", AdSize.SmartBanner, AdPosition.Bottom);
         AdRequest getAds = new AdRequest.Builder().Build();
         adsObject.LoadAd(getAds);
         }
 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-29 22:50:42

我终于做到了!

代码语言:javascript
复制
 using UnityEngine;
 using UnityEngine.UI;
 using System.Text;
 using System.Xml;
 using System.Collections;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Xml.Serialization;
 using System.IO;
 using GoogleMobileAds;
 using GoogleMobileAds.Api;

 public class responder : MonoBehaviour
 {
     private InterstitialAd adObject;

     private int gecis;

     public Text questionsorular;
     public Text responseA;
     public Text responseB;
     public Text responseC;
     public Text responseD;
     public Text infoResponses;
     public Text infoResponses1;
     public Text example;
     public Text dogrusayisi;

     private float corrects;
     private float questoesquestions;
     private float media;
     private int Notice;
 }

 void Start()
 {
     GetNewAds( null, null );
 }

 public void response(string alternative)
 {


     if (alternative == "A")
     {
         if (responseA.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }

     else if (alternative == "B")
     {
         if (responseB.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }

     else if (alternative == "C")
     {
         if (responseC.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }

     else if (alternative == "D")
     {
         if (responseD.text == infoResponses.text)
         {
             corrects += 1;
             nextQuestion();
         }
         else
         {
             Invoke("wrong", 1);
         }
     }
 }

 void wrong()
 {
     StartCoroutine(ShowAds());
     Application.LoadLevel("Notice");
 }

IEnumerator ShowAds()
    {
        while( !adObject.IsLoaded() )
            yield return null;

        adObject.Show();
    }

    public void GetNewAds( object sender, EventArgs args )
    {
        if( adObject != null )
            adObject.Destroy();

        adObject = new InterstitialAd( "AD UNIT ID" );
        adObject.AdClosed += GetNewAds;

        AdRequest GetAds = new AdRequest.Builder().Build();
        adObject.LoadAd( GetAds );
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33972900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档