繁体   English   中英

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

[英]Unity: Find out, if user has clicked on an ad

在我的统一应用中,我集成了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(); 

我这样做是因为在Mono开发中您无法使用对象,因此它必须是静态的。 但尽管如此:

因此,我认为广告类“ OnAdLeftApplication()”中的函数会在用户每次点击广告并因此离开应用程序时触发。 如果他或她这样做,我将用33枚硬币奖励此人!

但它不起作用。 可能不是因为我只是从插页式广告中调用“ show()”函数,但我不知道。

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

Thansk!

您可以将admobEventHandler用于特定的事件类型onAdOpenedonAdLeftApplication请检查github Wiki页面上的更多事件类型。

在调用interstitial.LoadAd之前,您必须先将interstial订阅到该事件。 例如interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;

public void HandleInterstitialLeftApplication(object sender, EventArgs args)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM