gpt4 book ai didi

c# - Unity : Find out, 如果用户点击了广告

转载 作者:搜寻专家 更新时间:2023-11-01 07:45:03 25 4
gpt4 key购买 nike

在我的 unity 应用程序中,我集成了 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);
}

当我在另一个类(class)打电话时(例如,点击按钮时),广告确实显示得很完美:)

Ads.Interstitial.Show(); 

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

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

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

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

谢谢!

最佳答案

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

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

public void HandleInterstitialLeftApplication(object sender, EventArgs args)

关于c# - Unity : Find out, 如果用户点击了广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46490123/

25 4 0
文章推荐: java - ArrayList 中的不兼容类型错误