gpt4 book ai didi

unity3d - Game Unity 上未显示广告

转载 作者:行者123 更新时间:2023-12-04 01:52:26 25 4
gpt4 key购买 nike

我使用以下代码在我的 Unity 游戏中放置横幅广告,但我的广告既没有显示测试广告,也没有显示实际的 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);
}
}

最佳答案

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

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();
}

}

欲了解更多信息:
  • Admob Integration Tutorial
  • UNITY AdMob Problem Fixed Ads Not Showing
  • Google Mobile Ads Unity Plugin v3.4.0
  • 关于unity3d - Game Unity 上未显示广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52356325/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com