Answer the question
In order to leave comments, you need to log in
AdMob not working rewarded add re-view?
In general, the game has three resurrections with the help of ads when I view ads -=1. When attempts == 0 the ad button becomes inactive. But after the first resurrection, the second does not work. advertising script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GoogleMobileAds.Api;
public class AdsMobReward : MonoBehaviour
{
private string RewardedUnitId = "ca-app-pub-3940256099942544/5224354917";
private RewardedAd rewardedAd;
public Button showAd;
public void OnEnable()
{
rewardedAd = new RewardedAd(RewardedUnitId);
AdRequest adRequest = new AdRequest.Builder().Build();
rewardedAd.LoadAd(adRequest);
rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
}
private void HandleUserEarnedReward(object sender, Reward e)
{
int mon = PlayerPrefs.GetInt("Money");
int gold = PlayerPrefs.GetInt("Gold");
int life = PlayerPrefs.GetInt("LifeCount");
mon += 20;
gold += 1;
life -= 1;
PlayerPrefs.SetInt("Video",1);
PlayerPrefs.SetInt("Money",mon);
PlayerPrefs.SetInt("Gold",gold);
PlayerPrefs.SetInt("LifeCount",life);
}
public void Update(){
int life = PlayerPrefs.GetInt("Life");
if(life != 0 && life > 0){
showAd.interactable = true;
}
else if(life == 0 && life < 0) showAd.interactable = false;
}
public void ShowAd()
{
if (rewardedAd.IsLoaded()){
rewardedAd.Show();
}
}
}
Answer the question
In order to leave comments, you need to log in
After viewing the ad, you need to download it again using the following lines of code:
rewardedAd = new RewardedAd(RewardedUnitId);
AdRequest adRequest = new AdRequest.Builder().Build();
rewardedAd.LoadAd(adRequest);
rewardedAd.IsLoaded()
will return false
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question