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();
}
}
}
rewardedAd = new RewardedAd(RewardedUnitId);
AdRequest adRequest = new AdRequest.Builder().Build();
rewardedAd.LoadAd(adRequest);
rewardedAd.IsLoaded()
будет выдавать false
. 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);
}
rewardedAd = new RewardedAd(RewardedUnitId);
AdRequest adRequest = new AdRequest.Builder().Build();
rewardedAd.LoadAd(adRequest);