【问题标题】:Unity: Find out, if user has clicked on an adUnity:查明用户是否点击了广告
【发布时间】:2017-09-29 13:44:13
【问题描述】:

在我的统一应用程序中,我集成了 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()”函数,但我不知道。

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

谢谢!

【问题讨论】:

    标签: c# android unity3d admob


    【解决方案1】:

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

    在您致电interstitial.LoadAd之前,您必须为该事件订阅插页式广告。类似interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;

    public void HandleInterstitialLeftApplication(object sender, EventArgs args)
    

    【讨论】:

    • 谢谢。我确实读过,这就是我使用我的函数的原因: public static void onAdLeftApplication() { ChangeCoinValue.actualCoinValue += 33; PlayerPrefs.SetInt("TotalCoinValue", ChangeCoinValue.actualCoinValue); } 但点击广告时它不会触发。
    • 在调用 loadad 之前,您必须将事件订阅到事件的插页式广告中。我会编辑我的答案
    • 太棒了!这就是缺少的东西:)
    • 顶!这正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 2020-11-20
    • 2022-08-09
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    相关资源
    最近更新 更多