【发布时间】:2020-11-17 07:55:35
【问题描述】:
我设法测试了一个简单的应用,并且广告(横幅和插页式)按预期工作(测试的,因为真实的没有,我知道为什么)。
问题是我想将广告集成到我的主应用程序中。我是为横幅做的,它可以工作,但不知道如何处理插页式广告。对于测试应用程序,我在按下按钮时调用了一个函数,但在我的应用程序中,我不希望按下按钮来显示插页式广告,我希望每次玩家死亡时都会发生这种情况。而且我不知道该怎么做。
using System;
using UnityEngine;
using GoogleMobileAds.Api;
public class ads : MonoBehaviour
{
private BannerView bannerView;
private InterstitialAd interstitial;
private void RequestBanner()...
private void RequestInterstitial()
{
string adUnitId = "ca-app-pub-3940256099942544/1033173712";
this.interstitial = new InterstitialAd(adUnitId);
AdRequest request = new AdRequest.Builder().Build();
this.interstitial.LoadAd(request);
}
public void GameOverSoShowInterstitial()
{
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
}
void Start()
{
MobileAds.Initialize(initStatus => { });
this.RequestBanner();
this.RequestInterstitial();
}
}
^这是我的广告脚本 但它位于second scene named Menu,但由于插页式应该在玩家死亡时出现,我应该将那个游戏对象移动到other scene that is the actual game,因为在“菜单”部分是不可能死的。而且,为了检查广告何时出现,我应该使用 GameManager,对吗?在游戏场景中也是如此。
public void GameOver()
{
gameOver = true;
gameScore = score.GetComponent<Score>().getScore();
score.SetActive(false);
Invoke("ActivateGameOverCanvas", 1);
pauseBtn.SetActive(false);
}
^这是来自gamemanager的游戏结束部分,所以我想在这里我应该以某种方式介绍一条会生成插页式广告的指令,但我不知道。我也尝试将“广告”脚本添加到游戏管理器中,因此在游戏管理器执行 GameOver 函数结束时,从广告中调用 GameOverSoShowInterstitial,但它不起作用。
有什么想法吗? :(
【问题讨论】:
标签: android unity3d ads banner interstitial