Unity:了解用户是否点击过广告

时间:2017-09-29 13:44:13

标签: c# android unity3d admob

在我的团结应用中,我整合了Admob。 这是我的“广告”类中的代码:

public static InterstitialAd interstitial;


private void Start()
{
    RequestInterstitial();
}

public void StartAds()
{
    RequestInterstitial();

    if (interstitial.IsLoaded())
    {
        interstitial.Show();
    }
    else
    {
        Debug.Log("Interstitial wasn't loaded yet");
    }

    interstitial.Show(); 
}

public static void onAdLeftApplication()
{
    ChangeCoinValue.actualCoinValue += 33;
    PlayerPrefs.SetInt("TotalCoinValue", ChangeCoinValue.actualCoinValue);
}


private void RequestInterstitial()
{

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

当我在另一个班级并且打电话时(例如按下按钮时),广告确实显示完全正确:

Ads.Interstitial.Show(); 

我这样做,因为在单声道开发中你不能使用对象所以它需要是静态的。但尽管如此:

所以我认为我的广告类“OnAdLeftApplication()”中的函数 每次用户点击广告时都会触发,然后离开应用程序。如果他或她这样做,我会用33个硬币奖励这个人!

但它不起作用。也许不是因为我只是在我的插页式广告中调用“show()”功能,但我不知道。

您能否向我解释一下,当用户点击其中一个广告时,如何用硬币奖励用户?

Thansk!

1 个答案:

答案 0 :(得分:4)

您可以将admobEventHandler用于特定事件类型onAdOpenedonAdLeftApplication,查看github wiki page了解更多活动类型。

在致电interstitial.LoadAd之前,您必须订阅该事件的空间。像interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;

这样的东西
public void HandleInterstitialLeftApplication(object sender, EventArgs args)
相关问题