Unity5 admob插页式广告未在设备中实现
Unity5 admob interstitial not implementing in device
我将此脚本附加到主按钮 onclick 和 运行 统一,但它显示 DUMMY SHOW INTERSTITIAL
。当我在我的设备上部署时,它会显示消息 "unfortunately APP has stopped".
我通过小改动和一些大改动尝试了很多次,但每次它都显示 DUMMY INTERSTITIAL SHOW
,但是当 运行 我的应用程序在设备上时它给出了 SORRY, UNFORTUNATELY APP HAS STOPPED
的错误,这是我的主要代码。任何人都可以查看此代码并告诉我是否有任何错误或我应该如何处理 运行 这段代码。
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
using GoogleMobileAds;
using System;
public class AdMobController : MonoBehaviour {
InterstitialAd interstitial;
// Use this for initialization
void Start () {
//RequestBanner ();
RequestInterstitial ();
}
public void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "AD_UNIT_ID";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Initialize an 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);
// Called when an ad request has successfully loaded.
interstitial.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad;
// Called when an ad is clicked.
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
print("OnAdLoaded event received.");
// Handle the ad loaded event.
}
public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
print("Interstitial Failed to load: " + args.Message);
// Handle the ad failed to load event.
}
public void ChangeScene (int sceneToChangeTo) {
Application.LoadLevel (sceneToChangeTo);
interstitial.Show ();
}
}
我怀疑您缺少使用 Admob 所需的依赖项。
转到资产 --> Play Services Resolver - -> Android 解析器 --> 解析客户端 Jars。
这会将所有必需的依赖项导入到您的项目中。
首先调用
interstitial.Show
当您检查插页式广告是否准备好显示时的方法。您可以使用 admob api 中的方法。
您还可以解释一下当您在启动方法中调用方法时,您如何 运行 单击按钮的代码吗?
我将此脚本附加到主按钮 onclick 和 运行 统一,但它显示 DUMMY SHOW INTERSTITIAL
。当我在我的设备上部署时,它会显示消息 "unfortunately APP has stopped".
我通过小改动和一些大改动尝试了很多次,但每次它都显示 DUMMY INTERSTITIAL SHOW
,但是当 运行 我的应用程序在设备上时它给出了 SORRY, UNFORTUNATELY APP HAS STOPPED
的错误,这是我的主要代码。任何人都可以查看此代码并告诉我是否有任何错误或我应该如何处理 运行 这段代码。
using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
using GoogleMobileAds;
using System;
public class AdMobController : MonoBehaviour {
InterstitialAd interstitial;
// Use this for initialization
void Start () {
//RequestBanner ();
RequestInterstitial ();
}
public void RequestInterstitial()
{
#if UNITY_ANDROID
string adUnitId = "AD_UNIT_ID";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
// Initialize an 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);
// Called when an ad request has successfully loaded.
interstitial.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad;
// Called when an ad is clicked.
}
public void HandleOnAdLoaded(object sender, EventArgs args)
{
print("OnAdLoaded event received.");
// Handle the ad loaded event.
}
public void HandleOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
print("Interstitial Failed to load: " + args.Message);
// Handle the ad failed to load event.
}
public void ChangeScene (int sceneToChangeTo) {
Application.LoadLevel (sceneToChangeTo);
interstitial.Show ();
}
}
我怀疑您缺少使用 Admob 所需的依赖项。
转到资产 --> Play Services Resolver - -> Android 解析器 --> 解析客户端 Jars。
这会将所有必需的依赖项导入到您的项目中。
首先调用
interstitial.Show
当您检查插页式广告是否准备好显示时的方法。您可以使用 admob api 中的方法。 您还可以解释一下当您在启动方法中调用方法时,您如何 运行 单击按钮的代码吗?