所以我在我的统一android项目中添加了来自admob的横幅广告和插页式广告。所以我在我的测试设备上测试了它,我的横幅广告显示正常,但我的插页式广告不会显示。
我已经在每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()中调用了该方法。
那么问题出在哪里?我应该把这个脚本放在空对象上吗?
答案 0 :(得分:1)
如上所述添加权限并在更新中调用插页式广告,因为加载需要一段时间。感谢
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 :(得分:0)