I was using Unity ads on my android game and everything was working perfectly, except from some devices where Unity ads where not showing sometimes. So, I wanted to test Admob rewarded video to see if I could get a better performance. Here's the code I'm using for Admob:
public void RequestRewardBasedVideo()
{
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "ca-app-pub-243186545632812xxxxxxxxxxxx";
#elif UNITY_IPHONE
string adUnitId = "unused";
#else
string adUnitId = "unexpected_platform";
#endif
RewardBasedVideoAd rewardBasedVideo = RewardBasedVideoAd.Instance;
AdRequest request = new AdRequest.Builder().Build();
rewardBasedVideo.LoadAd(request, adUnitId);
showAdvertisment(rewardBasedVideo);
}
private void showAdvertisment(RewardBasedVideoAd rewardBasedVideo)
{
if (rewardBasedVideo.IsLoaded())
{
rewardBasedVideo.Show();
rewardBasedVideo.OnAdRewarded += HandleRewardBasedVideoRewarded;
}
}
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
//reward
}
I assigned the RequestRewardBasedVideo() to a button, but the issue is that the videos are not showing! I think I'm in the right path because when I click the button, the console logs:
Dummy .ctor
Dummy CreateRewardBasedVideoAd
Dummy LoadAd
Dummy IsLoaded
Dummy ShowRewardBasedVideoAd
I have already tried putting the app on my Android device and imported the Google Admob package for Unity, also configured the ads in the Admob panel. Anyone have any ideas for what I can do to solve this??
what if video isn't loaded? You need to handle that case, listen to load event and then hit show.