我正在尝试这样的事情: 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);
}
}
答案 0 :(得分:0)
我可以告诉您,您可以使用时间类来了解上次显示的广告,也可以使用变量说,例如在重新启动按钮单击时每隔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);
}
}