如何解决AdMob导致Fps下降?
我已经看到许多有关AdMob和Fps掉线的问题,但是我没有找到解决方案!目前,我正在创建一个简单的无尽的跑步者,当玩家死亡并显示插页式广告时。一切正常,问题在于重启后使用:
Scene manager.LoadScene(Scenemanager.GetActiveScene().buildIndex)
Fps几乎开始下降到无法播放的水平。我不知道是什么原因造成的,但是我确定这是由于AdMob(我试图在没有admob的情况下构建游戏,并且一切正常。)每当玩家击中一个对象时,就会调用AdMob脚本。
这是我的admob代码:
public class AdMob : MonoBehaviour
{
string App_ID = "*************************************";
string Interstitial_ID = "ca-app-pub-3940256099942544/1033173712";
private InterstitialAd interstitial;
// Start is called before the first frame update
void Start()
{
MobileAds.Initialize(App_ID);
RequestInterstitial();
}
public void RequestInterstitial()
{
if (this.interstitial != null)
{
this.interstitial.Destroy();
}
this.interstitial = new InterstitialAd(Interstitial_ID);
// Called when an ad request has successfully loaded.
this.interstitial.OnAdLoaded += HandleOnAdLoaded;
// Called when an ad request failed to load.
this.interstitial.OnAdFailedToLoad += HandleOnAdFailedToLoad;
// Called when an ad is shown.
this.interstitial.OnAdOpening += HandleOnAdOpened;
// Called when the ad is closed.
this.interstitial.OnAdClosed += HandleOnAdClosed;
// Called when the ad click caused the user to leave the application.
this.interstitial.OnAdLeavingApplication += HandleOnAdLeavingApplication;
AdRequest request = new AdRequest.Builder().Build();
this.interstitial.LoadAd(request);
}
public void ShowInterstitialAd()
{
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
}
private void OnDisable()
{
this.interstitial.Destroy();
}
public void HandleOnAdLoaded(object sender,EventArgs args)
{
MonoBehaviour.print("HandleAdLoaded event received");
}
public void HandleOnAdFailedToLoad(object sender,AdFailedToLoadEventArgs args)
{
MonoBehaviour.print("HandleFailedToReceiveAd event received with message: "
+ args.Message);
}
public void HandleOnAdOpened(object sender,EventArgs args)
{
MonoBehaviour.print("HandleAdOpened event received");
}
public void HandleOnAdClosed(object sender,EventArgs args)
{
if (this.interstitial != null)
{
this.interstitial.Destroy();
}
}
public void HandleOnAdLeavingApplication(object sender,EventArgs args)
{
MonoBehaviour.print("HandleAdLeavingApplication event received");
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。