我对统一应用程序的admob遇到问题,我使用文档添加了admob,我使用了youtube上的视频教程,并尝试了演示应用程序(来自admob的hello world),但结果是相同的,没有出现广告横幅在我的应用中,如果使用插页式广告,当我尝试显示它时,我的应用会崩溃。但是,在控制台中有一条虚拟消息。
我的代码
using GoogleMobileAds.Api;
public class AdMobManager : MonoBehaviour {
private BannerView bannerView;
[SerializeField] private string appID = "";
[SerializeField] private string bannerID = "";
[SerializeField] private string regularAD = "";
private void Awake(){
MobileAds.Initialize(appID);
}
public void OnClickShowBanner() {
this.RequestBanner();
}
public void OnClickShowAd() {
this.RequestReqularAd();
}
private void RequestReqularAd() {
InterstitialAd AD = new InterstitialAd(regularAD);
AdRequest request = new AdRequest.Builder().Build();
AD.LoadAd(request);
}
public void RequestBanner() {
bannerView = new BannerView(bannerID, AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder().Build();
bannerView.LoadAd(request);
}
}
答案 0 :(得分:0)
您可以将此简单代码用于admob横幅。有时需要花费一些时间来显示横幅广告,但是此脚本可以正常工作。 Source
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
private BannerView bannerView;
public void Start()
{
this.RequestBanner();
}
private void RequestBanner()
{
#if UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/6300978111";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/2934735716";
#else
string adUnitId = "unexpected_platform";
#endif
// Create a 320x50 banner at the top of the screen.
bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top);
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the banner with the request.
bannerView.LoadAd(request);
}
}
答案 1 :(得分:0)
可用的源代码https://github.com/unity-plugins/Unity-Admob/blob/master/AdmobPluginRes/admobdemo.cs
"Process is running."