- Home /
Question by
vanjasretenovic123 · Feb 05, 2018 at 05:42 PM ·
adsunity ads
Unity AdMob Rewarded Video is not showing
Here is my code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api;
public class GoogleAdMobADS : MonoBehaviour { public bool pr; // Use this for initialization private RewardBasedVideoAd rewardBasedVideo;
public void Start()
{
pr = false;
// Get singleton reward based video ad reference.
//this.rewardBasedVideo = RewardBasedVideoAd.Instance;
// Get singleton reward based video ad reference.
this.rewardBasedVideo = RewardBasedVideoAd.Instance;
this.RequestRewardedVideo();
}
// Update is called once per frame
void Update () {
if (rewardBasedVideo.IsLoaded())
{
pr=true;
rewardBasedVideo.Show();
}
}
private void RequestRewardedVideo()
{
//ca-app-pub-3940256099942544/5224354917
string adUnitId = "ca-app-pub-3940256099942544/5224354917";
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the rewarded video ad with the request.
rewardBasedVideo.LoadAd(request, adUnitId);
}
}
I wrote this code in the script and added that script to empty game object on the scene. After that I made game and tested the game on Android device, but before that I had tested game in unity editor too. Ads are not showing. Thank you in advance!
Comment
Answer by winxalex · Oct 04, 2018 at 05:51 PM
IEnumerator WaitVideoToLoad() {
while (!_rewardBasedVideo.IsLoaded()) {
Debug.Log("Wait video 1s");
yield return new WaitForSeconds(1);
}
rewardBasedVideo.Show();
}
But this wont work. You need to subscribe to onAdLoaded event:
this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
rewardBasedVideo.Show();
}
Your answer
Follow this Question
Related Questions
Android build error when using Unity Ads 2 Answers
How to use the new Unity ads? 1 Answer