Unity3d Admob奖励视频广告
我无法在Unity3d中显示来自admob插件的奖励视频广告。
首先,这是我的脚本:
I'm having troubles showing the rewarded video ad from admob plugin in Unity3d. First of all this is my script:
using GoogleMobileAds.Api;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class AdManager : MonoBehaviour {
private RewardBasedVideoAd rewardBasedVideo;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public 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);
//Show Ad
showAdd(rewardBasedVideo);
}
private void showAdd(RewardBasedVideoAd rewardBasedVideo)
{
if (rewardBasedVideo.IsLoaded())
{
//Subscribe to Ad event
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
rewardBasedVideo.Show();
}
}
private void HandleRewardBasedVideoRewarded(object sender, Reward e)
{
Debug.Log("30 monedas ;)");
Debug.Log(e);
}
}
我运行 RequestRewardVideo( )
带有按钮的方法,但没有任何反应。我试图在 start()
和 showAdd()中运行
形成按钮,但仅显示视频1/3次...这有什么问题? requestrewardvideo()
方法
I run the RequestRewardVideo()
Method with a button, but nothing happens. I tried to run the requestrewardvideo()
method in the start()
and showAdd()
form the button but only shows the video 1/3 times... whats wrong with this?
预先感谢
我使用按钮运行 RequestRewardVideo()
方法,但没有任何反应。
I run the RequestRewardVideo()
Method with a button, but nothing happens.
您必须在加载和显示广告之间保持一定的时间差,因为广告加载需要一些时间。当您在加载 rewardBasedVideo.IsLoaded()
之后立即调用showAd时,返回false。
You must maintain some time difference between load and show Ad because Ad takes some time in loading. when you call in showAd just After loading rewardBasedVideo.IsLoaded()
return false.
因此调用 requestrewardvideo()
从 start()
并单击按钮单击呼叫 showAdd()
。
So call requestrewardvideo()
from start()
and on button Click call showAdd()
.
private void showAdd(RewardBasedVideoAd rewardBasedVideo) {
if (rewardBasedVideo.IsLoaded())
{
//Subscribe to Ad event
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
rewardBasedVideo.Show();
}else {
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideo.LoadAd(request, adUnitId);
}
}
在广告关闭并请求loadAd时也广告监听器再次在那里。这样每次 rewardBasedVideo.IsLoaded()
返回true。
Also Ad A listener When Ad Close and request to loadAd again there. So that each time rewardBasedVideo.IsLoaded()
return true.
编辑
rewardBasedVideo.OnAdClosed += HandleOnAdClosed; //Ad listener to your rewardBasedVideo
public void HandleOnAdClosed(object sender, EventArgs args)
{
// Load it here
}