1

我看到很多关于 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");
    }
}
4

0 回答 0