【发布时间】:2022-11-28 21:16:07
【问题描述】:
我添加了 admob 广告并编写了一个测试广告 ID。该广告在 unity 编辑器上运行,但我构建了我的游戏并安装了我的手机 .apk 广告不起作用。如果代码错误,它在编辑器中不起作用,所以我不要认为代码有什么问题。它可能与构建设置有关吗?
using System;
using System.Collections;
using System.Collections.Generic;
using GoogleMobileAds.Api;
using UnityEngine;
public class Rewarded : MonoBehaviour {
private InterstitialAd interstitial_Ad;
private RewardedAd rewardedAd;
private string interstitial_Ad_ID;
private string rewardedAd_ID;
void Update () {
}
void Start () {
interstitial_Ad_ID = "ca-app-pub-3940256099942544/1033173712";
rewardedAd_ID = "ca-app-pub-3940256099942544/5224354917";
MobileAds.Initialize (initStatus => { });
RequestInterstitial ();
RequestRewardedVideo ();
}
private void RequestInterstitial () {
interstitial_Ad = new InterstitialAd (interstitial_Ad_ID);
interstitial_Ad.OnAdLoaded += HandleOnAdLoaded;
AdRequest request = new AdRequest.Builder ().Build ();
interstitial_Ad.LoadAd (request);
}
private void RequestRewardedVideo () {
rewardedAd = new RewardedAd (rewardedAd_ID);
rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
rewardedAd.OnAdClosed += HandleRewardedAdClosed;
rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
AdRequest request = new AdRequest.Builder ().Build ();
rewardedAd.LoadAd (request);
}
public void ShowInterstitial () {
if (interstitial_Ad.IsLoaded ()) {
interstitial_Ad.Show ();
RequestInterstitial ();
}
}
public void ShowRewardedVideo () {
if (rewardedAd.IsLoaded ()) {
rewardedAd.Show ();
}
}
public void HandleOnAdLoaded (object sender, EventArgs args) {
}
public void HandleRewardedAdFailedToShow (object sender, AdErrorEventArgs args) {
RequestRewardedVideo ();
}
public void HandleRewardedAdClosed (object sender, EventArgs args) {
RequestRewardedVideo ();
}
public void HandleUserEarnedReward (object sender, Reward args) {
int coin = 30;
Coin.toplamCoin += coin;
PlayerPrefs.SetInt("kaydedilencoin", Coin.toplamCoin);
Debug.Log(PlayerPrefs.GetInt("kaydedilencoin"));
RequestRewardedVideo ();
}
}
我尝试进行许多不同的构建设置,但没有成功,例如像 R8 Active Debug Active 这样的设置。
【问题讨论】:
标签: unity3d admob admob-rewardedvideoad