首页 文章

为什么不会展示插页式广告?

提问于
浏览
1

所以我在我的统一android项目中添加了来自admob的 Banner 和插页式广告 . 所以我在我的测试设备上测试了它,我的 Banner 广告显示正常,但我的插页式广告不会显示 .

我已经在每11场比赛中展示了插页式广告:

public void OnCollisionEnter2D(Collision2D other)
    {

        if (other.gameObject.tag == "Pipe")
        {
            s.GameOver();
            targetVelocity.y = 0;
            targetVelocity.x = 0;
            cube.gameObject.SetActive(false);
            score.gameObject.SetActive(false);
            this.anime2.enabled = true;

        }


        PlayerPrefs.SetInt("Ad Counter", PlayerPrefs.GetInt("Ad Counter") + 1);

        if (PlayerPrefs.GetInt("Ad Counter") > 10)
        {
            if (interstitial.IsLoaded())
            {
                interstitial.Show();
            }

            PlayerPrefs.SetInt("Ad Counter", 0);
        }
    }

这是我的请求代码:

private void RequestInterstitial()

    {
#if UNITY_ANDROID

        string adUnitId ="ca-app -pub-3960055046097211/6145173288";

#elif UNITY_IPHONE

        string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";

#else

        string adUnitId = "unexpected_platform";

#endif

        // Initialize an InterstitialAd.

        InterstitialAd interstitial = new InterstitialAd(adUnitId);

        // Create an empty ad request.

        AdRequest request = new AdRequest.Builder().Build();

        // Load the interstitial with the request.

        interstitial.LoadAd(request);
    }

当然之后我在start()中调用了该方法 .

那问题出在哪里?我应该把这个脚本放在空对象上吗?

2 回答

  • 0

    如上所述添加权限并在更新中调用插页式广告,因为加载需要一段时间 . 谢谢

    enter code here
    
    InterstitialAd interstitial;
    bool check;
    
    private void RequestInterstitial()
    {
    
         interstitial = new InterstitialAd(adUnitId);
        AdRequest request = new AdRequest.Builder().Build();
        interstitial.LoadAd(request);
    
    }
    void Update()
    {
        if (!check) {
            if (interstitial.IsLoaded ()) {
                interstitial.Show ();
                check = true;
            }
        }
    }
    enter code here
    
  • 1

    如果您想使用非页内广告,则需要在Manifest文件中添加一些权限 .

    包含广告的广告活动 . 整个项目只需要一个,并请求允许使用互联网加载广告(如果您还没有要求他们用于其他内容):

    <manifest ...>
    
      <!-- Include required permissions for Google Mobile Ads to run-->
      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
      <application>
    
         //...
    
         <!--Include the AdActivity configChanges and theme. -->
         <activity android:name="com.google.android.gms.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
          android:theme="@android:style/Theme.Translucent" />
      </application>
    </manifest>
    

    Source .

相关问题