广告未在Game Unity上展示

问题描述 投票:2回答:1

我使用以下代码在我的团结游戏中放置横幅广告,但我的广告既没有显示测试广告也没有显示实际的admob广告。我不知道发生了什么,我已经在admob中完成了我的付款细节。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;

public class AdmobScript : MonoBehaviour 
{
     public string BannerId;

     void Start()
     {

        RequestBanner();


     }


     private void RequestBanner()
     {
     #if UNITY_EDITOR
     string adUnitId = "unused";

     #elif UNITY_ANDROID
         string adUnitId = BannerId;
     #elif UNITY_IPHONE
         string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
     #else
         string adUnitId = "unexpected_platform";
     #endif

         // Create a 320x50 banner at the bottom of the screen.
         BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, 
         AdPosition.Bottom);
         // Create an empty ad request.
         AdRequest request = new AdRequest.Builder().Build();
         // Load the banner with the request.
         bannerView.LoadAd(request);
     }
 }

unity3d google-play admob google-play-games banner-ads
1个回答
3
投票

您的代码中缺少一个函数来处理bannerView对象的show功能:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;

public class AdmobScript : MonoBehaviour 
{
     BannerView bannerView;

 void Start()
 {

    RequestBanner();
 }


 private void RequestBanner()
 {
 #if UNITY_EDITOR
 string adUnitId = "unused";

 #elif UNITY_ANDROID
     string adUnitId = BannerId;
 #elif UNITY_IPHONE
     string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
 #else
     string adUnitId = "unexpected_platform";
 #endif

     // Create a 320x50 banner at the bottom of the screen.
     BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, 
     AdPosition.Bottom);
     // Create an empty ad request.
     AdRequest request = new AdRequest.Builder().Build();
     // Load the banner with the request.
     bannerView.LoadAd(request);
     // Handle the show functionality of banner ads
     bannerView.OnAdLoaded+=HandleOnAdLoaded;
 }

 void HandleOnAdLoadeded(object a, EventArgs args) {
     print("loaded");
     bannerView.Show();
 }

}

更多信息:

© www.soinside.com 2019 - 2024. All rights reserved.