Admob rewarded ads is not rewarding after being build - unity3d

When I watching rewarded on Unity, there is no problem but after building when I watching rewarded, I don't get any rewards. I tried so hard and I can't find. Can you help me guys? Thank you in advance.
public class AdReward : MonoBehaviour
{
private RewardedAd rewardedAd;
int rewardAmount;
int coinn;
private void Start()
{
coinn= PlayerPrefs.GetInt("NumberOfCoins");
string adUnitId;
#if UNITY_ANDROID
adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
adUnitId = "unexpected_platform";
#endif
MobileAds.Initialize(initStatus => { });
this.rewardedAd = new RewardedAd(adUnitId);
rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the rewarded ad with the request.
this.rewardedAd.LoadAd(request);
}
public void HandleUserEarnedReward(object sender, Reward args)
{
double amount = args.Amount;
coinn += (int)amount*20;
PlayerPrefs.SetInt("NumberOfCoins", coinn);
}
public void UserChoseToWatchAd()
{
if (this.rewardedAd.IsLoaded())
{
this.rewardedAd.Show();
}
}
}

Related

The advertisement for Unity admob does not appear when conducting internal tests

When I directly insert the apk file into an android mobile device
MobileAds.Initialize(initStatus => { });
code works fine.
However, when I use it in an internal test version with aab file,
it does not work. How can I debug this in internal testing version?
public class BottomBanner : MonoBehaviour
{
public static BottomBanner instance;
private BannerView bannerView;
public TextMeshProUGUI FailMSG;
public AdRequest request;
private void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
Destroy(gameObject);
}
FailMSG.text += "\n is awake Ok "+ "\n version : " + GameStartManager.instance.version + "\n Test : " + GameStartManager.instance.isTest;
}
public void Start()
{
FailMSG.text += "\n Start 000 ";
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(initStatus => { });
FailMSG.text += "\n Start 111 ";
this.RequestBanner();
FailMSG.text += "\n Start 222 ";
}
private void RequestBanner()
{
#if UNITY_ANDROID
string adUnitId = null;
if (GameStartManager.instance.isTest)
{
adUnitId = "ca-app-pub-3940256099942544/6300978111";
}
else
{
adUnitId = "ca-app-pub-0000000000000000/1111111111"; // bannerID
}
#elif UNITY_IPHONE
string adUnitId = "unexpected_platform";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up banner ad before creating a new one.
if (this.bannerView != null)
{
this.bannerView.Destroy();
}
AdSize adaptiveSize = AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);
this.bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
// Create an empty ad request.
request = new AdRequest.Builder().Build();
// Load the banner with the request.
this.bannerView.LoadAd(request);
SceneManager.LoadScene(1);
}
public void ToggleBannerAd(bool b){
if (b) bannerView.Show();
else bannerView.Hide();
}
}

Google AdMob Unity: Only test ads work (in Unity Editor) but no real ads

My admob account is linked to the app in play store, status "ready", AdMob app ID also added into ad settings in Unity, added in the real ad unit ID, test ad showing in Unity, waited a week...
Result: no real ads
My event is calling RequestAndLoadInterstitialAd() and ShowInterstitialAd(), which works in Unity with the test ad. I expected it to work once the test ad implemented successfully.
using UnityEngine.Events;
using UnityEngine;
using GoogleMobileAds.Api;
using GoogleMobileAds.Common;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
public class GoogleAdMobController : MonoBehaviour
{
private AppOpenAd appOpenAd;
private BannerView bannerView;
private InterstitialAd interstitialAd;
private RewardedAd rewardedAd;
private RewardedInterstitialAd rewardedInterstitialAd;
private float deltaTime;
private bool isShowingAppOpenAd;
public UnityEvent OnAdLoadedEvent;
public UnityEvent OnAdFailedToLoadEvent;
public UnityEvent OnAdOpeningEvent;
public UnityEvent OnAdFailedToShowEvent;
public UnityEvent OnUserEarnedRewardEvent;
public UnityEvent OnAdClosedEvent;
public bool showFpsMeter = true;
public Text fpsMeter;
public Text statusText;
#region UNITY MONOBEHAVIOR METHODS
public void Start()
{
MobileAds.SetiOSAppPauseOnBackground(true);
List<String> deviceIds = new List<String>() { AdRequest.TestDeviceSimulator };
// Add some test device IDs (replace with your own device IDs).
#if UNITY_IPHONE
deviceIds.Add("b77a5c561934e089)--a185c62eba2497c95197140e5282b27a");
#elif UNITY_ANDROID
deviceIds.Add("b77a5c561934e089)--a185c62eba2497c95197140e5282b27a");
#endif
// Configure TagForChildDirectedTreatment and test device IDs.
RequestConfiguration requestConfiguration =
new RequestConfiguration.Builder()
.SetTagForChildDirectedTreatment(TagForChildDirectedTreatment.Unspecified)
.SetTestDeviceIds(deviceIds).build();
MobileAds.SetRequestConfiguration(requestConfiguration);
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(HandleInitCompleteAction);
}
private void HandleInitCompleteAction(InitializationStatus initstatus)
{
// Callbacks from GoogleMobileAds are not guaranteed to be called on
// main thread.
// In this example we use MobileAdsEventExecutor to schedule these calls on
// the next Update() loop.
MobileAdsEventExecutor.ExecuteInUpdate(() =>
{
statusText.text = "Initialization complete";
// RequestBannerAd();
});
}
private void Update()
{
if (showFpsMeter)
{
fpsMeter.gameObject.SetActive(true);
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
float fps = 1.0f / deltaTime;
fpsMeter.text = string.Format("{0:0.} fps", fps);
}
else
{
fpsMeter.gameObject.SetActive(false);
}
}
#endregion
#region HELPER METHODS
private AdRequest CreateAdRequest()
{
return new AdRequest.Builder()
.AddKeyword("unity-admob-sample")
.Build();
}
public void OnApplicationPause(bool paused)
{
// Display the app open ad when the app is foregrounded.
if (!paused)
{
ShowAppOpenAd();
}
}
#endregion
#region BANNER ADS
public void RequestBannerAd()
{
statusText.text = "Requesting Banner Ad.";
// These ad units are configured to always serve test ads.
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/6300978111";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/2934735716";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up banner before reusing
if (bannerView != null)
{
bannerView.Destroy();
}
// Create a 320x50 banner at top of the screen
bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
// Add Event Handlers
bannerView.OnAdLoaded += (sender, args) => OnAdLoadedEvent.Invoke();
bannerView.OnAdFailedToLoad += (sender, args) => OnAdFailedToLoadEvent.Invoke();
bannerView.OnAdOpening += (sender, args) => OnAdOpeningEvent.Invoke();
bannerView.OnAdClosed += (sender, args) => OnAdClosedEvent.Invoke();
// Load a banner ad
bannerView.LoadAd(CreateAdRequest());
}
public void DestroyBannerAd()
{
if (bannerView != null)
{
bannerView.Destroy();
}
}
#endregion
#region INTERSTITIAL ADS
public void RequestAndLoadInterstitialAd()
{
// statusText.text = "Requesting Interstitial Ad.";
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-2334240444886107/9358512518";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up interstitial before using it
if (interstitialAd != null)
{
interstitialAd.Destroy();
}
interstitialAd = new InterstitialAd(adUnitId);
// Add Event Handlers
interstitialAd.OnAdLoaded += (sender, args) => OnAdLoadedEvent.Invoke();
interstitialAd.OnAdFailedToLoad += (sender, args) => OnAdFailedToLoadEvent.Invoke();
interstitialAd.OnAdOpening += (sender, args) => OnAdOpeningEvent.Invoke();
interstitialAd.OnAdClosed += (sender, args) => OnAdClosedEvent.Invoke();
// Load an interstitial ad
interstitialAd.LoadAd(CreateAdRequest());
}
public void ShowInterstitialAd()
{
if (interstitialAd.IsLoaded())
{
interstitialAd.Show();
}
else
{
statusText.text = "Interstitial ad is not ready yet";
}
}
public void DestroyInterstitialAd()
{
if (interstitialAd != null)
{
interstitialAd.Destroy();
}
}
#endregion
#region REWARDED ADS
public void RequestAndLoadRewardedAd()
{
statusText.text = "Requesting Rewarded Ad.";
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
string adUnitId = "unexpected_platform";
#endif
// create new rewarded ad instance
rewardedAd = new RewardedAd(adUnitId);
// Add Event Handlers
rewardedAd.OnAdLoaded += (sender, args) => OnAdLoadedEvent.Invoke();
rewardedAd.OnAdFailedToLoad += (sender, args) => OnAdFailedToLoadEvent.Invoke();
rewardedAd.OnAdOpening += (sender, args) => OnAdOpeningEvent.Invoke();
rewardedAd.OnAdFailedToShow += (sender, args) => OnAdFailedToShowEvent.Invoke();
rewardedAd.OnAdClosed += (sender, args) => OnAdClosedEvent.Invoke();
rewardedAd.OnUserEarnedReward += (sender, args) => OnUserEarnedRewardEvent.Invoke();
// Create empty ad request
rewardedAd.LoadAd(CreateAdRequest());
}
public void ShowRewardedAd()
{
if (rewardedAd != null)
{
rewardedAd.Show();
}
else
{
statusText.text = "Rewarded ad is not ready yet.";
}
}
public void RequestAndLoadRewardedInterstitialAd()
{
statusText.text = "Requesting Rewarded Interstitial Ad.";
// These ad units are configured to always serve test ads.
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/5354046379";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/6978759866";
#else
string adUnitId = "unexpected_platform";
#endif
// Create an interstitial.
RewardedInterstitialAd.LoadAd(adUnitId, CreateAdRequest(), (rewardedInterstitialAd, error) =>
{
if (error != null)
{
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "RewardedInterstitialAd load failed, error: " + error;
});
return;
}
this.rewardedInterstitialAd = rewardedInterstitialAd;
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "RewardedInterstitialAd loaded";
});
// Register for ad events.
this.rewardedInterstitialAd.OnAdDidPresentFullScreenContent += (sender, args) =>
{
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "Rewarded Interstitial presented.";
});
};
this.rewardedInterstitialAd.OnAdDidDismissFullScreenContent += (sender, args) =>
{
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "Rewarded Interstitial dismissed.";
});
this.rewardedInterstitialAd = null;
};
this.rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += (sender, args) =>
{
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "Rewarded Interstitial failed to present.";
});
this.rewardedInterstitialAd = null;
};
});
}
public void ShowRewardedInterstitialAd()
{
if (rewardedInterstitialAd != null)
{
rewardedInterstitialAd.Show((reward) => {
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "User Rewarded: " + reward.Amount;
});
});
}
else
{
statusText.text = "Rewarded ad is not ready yet.";
}
}
#endregion
#region APPOPEN ADS
public void RequestAndLoadAppOpenAd()
{
statusText.text = "Requesting App Open Ad.";
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/3419835294";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/5662855259";
#else
string adUnitId = "unexpected_platform";
#endif
// create new app open ad instance
AppOpenAd.LoadAd(adUnitId, ScreenOrientation.Portrait, CreateAdRequest(), (appOpenAd, error) =>
{
if (error != null)
{
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "AppOpenAd load failed, error: " + error;
});
return;
}
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "AppOpenAd loaded. Please background the app and return.";
});
this.appOpenAd = appOpenAd;
});
}
public void ShowAppOpenAd()
{
if (isShowingAppOpenAd)
{
return;
}
if (appOpenAd == null)
{
return;
}
// Register for ad events.
this.appOpenAd.OnAdDidDismissFullScreenContent += (sender, args) =>
{
isShowingAppOpenAd = false;
MobileAdsEventExecutor.ExecuteInUpdate(() => {
Debug.Log("AppOpenAd dismissed.");
if (this.appOpenAd != null)
{
this.appOpenAd.Destroy();
this.appOpenAd = null;
}
});
};
this.appOpenAd.OnAdFailedToPresentFullScreenContent += (sender, args) =>
{
isShowingAppOpenAd = false;
var msg = args.AdError.GetMessage();
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "AppOpenAd present failed, error: " + msg;
if (this.appOpenAd != null)
{
this.appOpenAd.Destroy();
this.appOpenAd = null;
}
});
};
this.appOpenAd.OnAdDidPresentFullScreenContent += (sender, args) =>
{
isShowingAppOpenAd = true;
MobileAdsEventExecutor.ExecuteInUpdate(() => {
Debug.Log("AppOpenAd presented.");
});
};
this.appOpenAd.OnAdDidRecordImpression += (sender, args) =>
{
MobileAdsEventExecutor.ExecuteInUpdate(() => {
Debug.Log("AppOpenAd recorded an impression.");
});
};
this.appOpenAd.OnPaidEvent += (sender, args) =>
{
string currencyCode = args.AdValue.CurrencyCode;
long adValue = args.AdValue.Value;
string suffix = "AppOpenAd received a paid event.";
MobileAdsEventExecutor.ExecuteInUpdate(() => {
string msg = string.Format("{0} (currency: {1}, value: {2}", suffix, currencyCode, adValue);
statusText.text = msg;
});
};
appOpenAd.Show();
}
#endregion
#region AD INSPECTOR
public void OpenAdInspector()
{
statusText.text = "Open Ad Inspector.";
MobileAds.OpenAdInspector((error) =>
{
if (error != null)
{
string errorMessage = error.GetMessage();
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "Ad Inspector failed to open, error: " + errorMessage;
});
}
else
{
MobileAdsEventExecutor.ExecuteInUpdate(() => {
statusText.text = "Ad Inspector closed.";
});
}
});
}
#endregion
}
If your test device (You can add this from Admob) shows your ADs as expected you should be fine. After some requests, your game will start to show real ads. Admob does not give real ads immediately, it needs some request to show real ads. But as I say you have to be sure your test devices show ads correctly.
And I also recommend check compatible admob SDK and Unity versions. Because they have bugs sometimes. You can check it in Admob GitHub page.
You can check here:
https://github.com/googleads/googleads-mobile-unity/releases
There were two things wrong. One, I was using my live adUnit ID not the test one. The second issue was I was calling the load and show methods at the same time which worked in Unity, but on Android it seems there needs to be more time for the ad to load.
What I did to get the test ads on mobile device:
Set up the test device like HTugsadK said https://support.google.com/admob/answer/9691433
Change the adUnitId in RequestAndLoadInterstitialAd() to the interstitial test ID from here https://developers.google.com/admob/unity/test-ads#add_your_test_device_programmatically
For production this should be changed back to the real adUnitId.
Change the end of the RequestAndLoadInterstitialAd() method and Invoke the show method with a 5 second delay. Now in your event you only have to call this method.
public void RequestAndLoadInterstitialAd()
{
// statusText.text = "Requesting Interstitial Ad.";
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/1033173712";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
string adUnitId = "unexpected_platform";
#endif
// Clean up interstitial before using it
if (interstitialAd != null)
{
interstitialAd.Destroy();
}
interstitialAd = new InterstitialAd(adUnitId);
// Add Event Handlers
interstitialAd.OnAdLoaded += (sender, args) => OnAdLoadedEvent.Invoke();
interstitialAd.OnAdFailedToLoad += (sender, args) => OnAdFailedToLoadEvent.Invoke();
interstitialAd.OnAdOpening += (sender, args) => OnAdOpeningEvent.Invoke();
interstitialAd.OnAdClosed += (sender, args) => OnAdClosedEvent.Invoke();
// Load an interstitial ad
interstitialAd.LoadAd(CreateAdRequest());
Invoke("ShowInterstitialAd", 5);
}

Unity Rewarded Interstitial with Google Mobile Ads v6.0.2 - code from tutorial doesn't work

I am trying to add an ad to my game in Unity, but unfortunately using the example in the official google guide (developers.google.com/admob/unity/rewarded-interstitial), I get an error. Can anybody help me solve this problem?
public void Start()
{
string adUnitId;
#if UNITY_ANDROID
adUnitId = trueRewardedAdId;
#elif UNITY_EDITOR
adUnitId = fakeRewardedAdId;
#else
adUnitId = "unexpected_platform";
#endif
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the rewarded ad with the request.
// Create an interstitial.
RewardedInterstitialAd.LoadAd(adUnitId, request, AdLoadCallback);
}
private void AdLoadCallback(RewardedInterstitialAd ad, string error)
{
if (error == null)
{
rewardedInterstitialAd = ad;
rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += HandleAdFailedToPresent;
rewardedInterstitialAd.OnAdDidPresentFullScreenContent += HandleAdDidPresent;
rewardedInterstitialAd.OnAdDidDismissFullScreenContent += HandleAdDidDismiss;
rewardedInterstitialAd.OnPaidEvent += HandlePaidEvent;
}
}
Update LoadAd() to use an action as a parameter, and change the parameter 'error' type from string to AdFailedToLoadEventArgs in the callback.
public void Start()
{
...
RewardedInterstitialAd.LoadAd(adUnitId, request, (req,err) =>
adLoadCallback(req, err));
}
private void AdLoadCallback(RewardedInterstitialAd ad, AdFailedToLoadEventArgs error)
{
...
}

Reward ad callback is not firing

i have a game and when the player loses their lives, i want them to be able to watch a video for a second chance.
I am using unity version 2018.1.1f1 person and i have downloaded the admob unity plugin version 3.13.1
So if the player agrees to watch an ad, the ad will play and then resume the game without firing the callback that rewards the player. This is my code:
using System;
using UnityEngine;
using GoogleMobileAds.Api;
using UnityEngine.UI;
public class RewardAd : MonoBehaviour {
private BannerView bannerView;
private InterstitialAd interstitial;
private RewardBasedVideoAd rewardBasedVideo;
private float deltaTime = 0.0f;
private static string outputMessage = string.Empty;
public AudioSource musicPlayer;
public Player player;
public Text UIText;
public static string OutputMessage
{
set { outputMessage = value; }
}
public void Start()
{
#if UNITY_ANDROID
string appId = "ca-app-pub-3940256099942544~3347511713";
#elif UNITY_IPHONE
string appId = "ca-app-pub-3940256099942544~1458002511";
#else
string appId = "unexpected_platform";
#endif
MobileAds.SetiOSAppPauseOnBackground(true);
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(appId);
//Get singleton reward based video ad reference.
this.rewardBasedVideo = RewardBasedVideoAd.Instance;
// RewardBasedVideoAd is a singleton, so handlers should only be registered once.
this.rewardBasedVideo.OnAdLoaded += this.HandleRewardBasedVideoLoaded;
this.rewardBasedVideo.OnAdFailedToLoad += this.HandleRewardBasedVideoFailedToLoad;
this.rewardBasedVideo.OnAdOpening += this.HandleRewardBasedVideoOpened;
this.rewardBasedVideo.OnAdStarted += this.HandleRewardBasedVideoStarted;
this.rewardBasedVideo.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
this.rewardBasedVideo.OnAdClosed += this.HandleRewardBasedVideoClosed;
this.rewardBasedVideo.OnAdLeavingApplication += this.HandleRewardBasedVideoLeftApplication;
}
public void Update()
{
// Calculate simple moving average for time to render screen. 0.1 factor used as smoothing
// value.
this.deltaTime += (Time.deltaTime - this.deltaTime) * 0.1f;
}
// Returns an ad request with custom ad targeting.
private AdRequest CreateAdRequest()
{
return new AdRequest.Builder()
.AddTestDevice(AdRequest.TestDeviceSimulator)
.AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
.AddKeyword("game")
.SetGender(Gender.Male)
.SetBirthday(new DateTime(1985, 1, 1))
.TagForChildDirectedTreatment(false)
.AddExtra("color_bg", "9B30FF")
.Build();
}
private void RequestRewardBasedVideo()
{
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
string adUnitId = "ca-app-pub-7624023175090985/4535603801";
#else
string adUnitId = "unexpected_platform";
#endif
this.rewardBasedVideo.LoadAd(this.CreateAdRequest(), adUnitId);
}
private void ShowInterstitial()
{
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
else
{
MonoBehaviour.print("Interstitial is not ready yet");
}
}
private void ShowRewardBasedVideo()
{
if (this.rewardBasedVideo.IsLoaded())
{
this.rewardBasedVideo.Show();
}
else
{
MonoBehaviour.print("Reward based video ad is not ready yet");
}
}
#region RewardBasedVideo callback handlers
public void HandleRewardBasedVideoLoaded(object sender, EventArgs args)
{
this.rewardBasedVideo.Show();
UIText.text = "Watch a short video\nfor an extra life ?";
}
public void HandleRewardBasedVideoFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
UIText.text = "Watch a short video\nfor an extra life ?";
}
public void HandleRewardBasedVideoOpened(object sender, EventArgs args)
{
musicPlayer.Pause();
player.disableMovment = true;
}
public void HandleRewardBasedVideoStarted(object sender, EventArgs args)
{
musicPlayer.Pause();
player.disableMovment = true;
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
UIText.text = "Watch a short video\nfor an extra life ?";
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
player.rewardAdUI.SetActive(false);
UIText.text = "Watch a short video\nfor an extra life ?";
player.disableMovment = false;
if (PlayerPrefs.GetInt("music") == 1)
{
musicPlayer.Play();
}
Lives.addLives(1);
player.RespawnPlayer();
}
public void HandleRewardBasedVideoLeftApplication(object sender, EventArgs args)
{
UIText.text = "Watch a short video\nfor an extra life ?";
}
public void secondChance()
{
UIText.text = "Loading video...\nplease wait.";
this.RequestRewardBasedVideo();
}
public void GameOver()
{
player.disableMovment = false;
if (PlayerPrefs.GetInt("music") == 1)
{
musicPlayer.Play();
}
player.gameOver();
}
#endregion
}
So the 2nd to last function called secondChance() is what runs to play the ad. On my android device, this plays the test rewarded video.
After the ad plays, the HandleRewardBasedVideoRewarded function should be called but it doesnt. Any help at all is appriciated
I found a Silent Error after debugging in Android Studio, its due to threading issues in Unity.
Solution : Call your handling event in main thread (in Update Method)
bool isAdClosed = false;
bool isRewarded = false;
void Update()
{
if (isAdClosed)
{
if (isRewarded)
{
// do all the actions
// reward the player
isRewarded = false;
}
else
{
// Ad closed but user skipped ads, so no reward
// Ad your action here
}
isAdClosed = false; // to make sure this action will happen only once.
}
}
public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
{
print("HandleRewardBasedVideoClosed event received");
RequestRewardBasedVideo(); // to load Next Videoad
isAdClosed = true;
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
string type = args.Type;
double amount = args.Amount;
print("HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " +
type);
isRewarded = true;
}
Vivek's solution worked for me on Unity v20212.1.15f1, although I had to put the code in my GameManager Update function as the AdManager Update function wasn't running when the RewardedAd was shown.

rewarded video ad is not showing unity android game

I have developed an app. In which, to access level a player needs to purchase or watch rewarded video. To watch a rewarded video player needs to press or tap a button. but when i press a button, nothing is happening!!
I have created a file "AdManager.cs" and the code is as follows:
public class AdManager : MonoBehaviour {
// before codes
.
.
.
//I have created an instance to admanager
public static AdManager Instance {set;get;}
.
.
.
.
void Awake(){
Instance=this;
}
.
.
.
.
//few more codes
.
.
.
public void showRewardBasedVideoAd(){
#if UNITY_ANDROID
string adUnitId = "xxxxxxxxxxxxxxxxxxxxxxx";
#elif UNITY_IPHONE
string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
rewardBasedVideoAd = RewardBasedVideoAd.Instance;
rewardBasedVideoAd.OnAdLoaded += HandleOnrewardBasedVideoAdLoaded;
rewardBasedVideoAd.OnAdFailedToLoad += HandleOnrewardBasedVideoAdFailedToLoad;
rewardBasedVideoAd.OnAdOpening += HandleOnrewardBasedVideoAdOpening;
rewardBasedVideoAd.OnAdRewarded += HandleOnrewardBasedVideoAdRewarded;
rewardBasedVideoAd.OnAdClosed += HandleOnrewardBasedVideoAdClosed;
rewardBasedVideoAd.OnAdLeavingApplication += HandleOnrewardBasedVideoAdLeavingApplication;
AdRequest request = new AdRequest.Builder ().Build();
rewardBasedVideoAd.LoadAd (request, adUnitId);
if (rewardBasedVideoAd.IsLoaded ()) {
rewardBasedVideoAd.Show ();
} else {
Debug.Log ("Rewarded Video Ad is not Yet ready!!!!");
}
}
public void HandleOnrewardBasedVideoAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
print("Interstitial Failed to load: " + args.Message);
}
public void HandleOnrewardBasedVideoAdLoaded(object sender, EventArgs args)
{
print("OnAdLoaded event received.");
}
public void HandleOnrewardBasedVideoAdOpening(object sender, EventArgs args)
{
print("OnAdLoaded event received.");
}
public void HandleOnrewardBasedVideoAdClosed(object sender, EventArgs args)
{
print("OnAdLoaded event received.");
}
public void HandleOnrewardBasedVideoAdLeavingApplication(object sender, EventArgs args)
{
print("OnAdLoaded event received.");
}
public void HandleOnrewardBasedVideoAdRewarded(object sender, Reward args)
{
string type = args.Type;
double amount = args.Amount;
print("User rewarded with: " + amount.ToString() + " " + type);
totalPoints += 100;
Debug.Log("100granted");
}
// rest codes
}
I am developing this app in unity and for android platform.
I have created unityad mediation in admob rewarded video adunit section. There is mark which is saying pending. I could not able to figure out where is the problem.
Guide me in this regard!!
If you are using only one network to show rewarded video you can simply use Unity ADS SDK without any medation.
I had same problem and after few months I gave up. I used Admob for banners/interstitials and UnityAds for rewarded Video and it's working great.