我在Unity游戏中使用AdMob奖励视频。我有两个问题:
文档说明您需要设置中介网络,我还没有设置任何广告。怎么样?
如何检测用户是否完成了视频?只有在视频完成后才会触发任何方法。
答案 0 :(得分:1)
您确定从其他网络获得了奖励视频广告,而不仅仅是内置的Admob广告吗?
第二个问题的答案可以在the Firebase documentation here中找到。
基本上,您创建一个RewardBasedVideoAd实例并将OnAdRewarded事件处理程序附加到它:
private void RequestRewardBasedVideo(){
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "INSERT_AD_UNIT_HERE";
#elif UNITY_IPHONE
string adUnitId = "INSERT_AD_UNIT_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideo.LoadAd(request, adUnitId);
}
...
// Reward based video instance is a singleton. Register handlers once to
// avoid duplicate events.
if (!rewardBasedEventHandlersSet){
// Ad event fired when the rewarded video ad
// has been received.
rewardBasedVideo.OnAdLoaded += HandleRewardBasedVideoLoaded;
// has failed to load.
rewardBasedVideo.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
// is opened.
rewardBasedVideo.OnAdOpening += HandleRewardBasedVideoOpened;
// has started playing.
rewardBasedVideo.OnAdStarted += HandleRewardBasedVideoStarted;
// has rewarded the user.
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
// is closed.
rewardBasedVideo.OnAdClosed += HandleRewardBasedVideoClosed;
// is leaving the application.
rewardBasedVideo.OnAdLeavingApplication += HandleRewardBasedVideoLeftApplication;
rewardBasedEventHandlersSet = true;
}
...
public void HandleRewardBasedVideoRewarded(object sender, Reward args){
string type = args.Type;
double amount = args.Amount;
print("User rewarded with: " + amount.ToString() + " " + type);
}
答案 1 :(得分:0)
How to integrate Admob Rewarded Video到Unity3d应用程序? 以下是创建admob视频的最小代码。
Admob.Instance().loadRewardedVideo("ca-app-pub-3940256099942544/1712485313");
使用插页式广告进行模拟,视频需要在应用中的相应停靠点显式显示,在显示之前检查视频是否已就绪:
if (Admob.Instance().isRewardedVideoReady()) {
Admob.Instance().showRewardedVideo();
}
处理视频事件
Admob.Instance().onRewardedVideoStarted += myRewardedVideoStartedFun ;
Admob.Instance().onRewarded += myRewardedFun ;