【问题标题】:How to Show Admob Interstitials on Counted Click?如何在计数点击时显示 Admob 插页式广告?
【发布时间】:2018-08-03 20:24:36
【问题描述】:

我正在尝试这样的事情: if button clicked for 4 times, I could show Interstitial?

但是我做不到。

创建了一个游戏对象。 将脚本附加到该对象。 创建了一个重新启动按钮。 仅使用 onclick-runtime 等在该按钮上实现此对象。

现在每次用户点击重新启动按钮时,插页式广告都会自动显示。但当然你可能知道,这很烦人。

我不知道如何计算用户按下重新启动按钮的次数,例如,如果用户按下按钮,则每 3 或 4 次显示广告。

谢谢。

using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;

public class AdScript : MonoBehaviour
{
    InterstitialAd interstitial;

    public string InterstitialId;

    // Use this for initialization
    void Start()
    {
        //Request Ads
        //RequestBanner();
        RequestInterstitial();
    }

    public void showInterstitialAd()
    {
        //Show Ad
        if (interstitial.IsLoaded())
        {
            interstitial.Show();
        }
    }

    private void RequestInterstitial()
    {
        string adUnitId = InterstitialId;

        // 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);
    }

}

【问题讨论】:

    标签: unity3d admob


    【解决方案1】:

    我可以给你一个想法,你可以使用时间类来知道最后展示的广告或使用变量说,比如在重启按钮点击时每 4 个游戏展示广告。

    using UnityEngine;
    using System.Collections;
    using GoogleMobileAds.Api;
    
    public class AdScript : MonoBehaviou
    {
    int counter =0;
    InterstitialAd interstitial;
    
    public string InterstitialId;
    
    // Use this for initialization
    void Start()
    {
    //Request Ads
    //RequestBanner();
    RequestInterstitial();
    }
    
    public void showInterstitialAd()
    {
        counter ++;
        if(counter%4==0)
        {
        //Show Ad
            if (interstitial.IsLoaded())
            {
               interstitial.Show();
            }
        }
    }
    
    private void RequestInterstitial()
    {
        string adUnitId = InterstitialId;
    
        // 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);
    }
    

    }

    【讨论】:

    • 如果您能显示我应该输入的内容,我将不胜感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多