I recently face an issue with my google ads - Test ads are running perfectly but when I put my id to this code, this doesn’t work at all. Can anyone help me with this issue?
using UnityEngine;
using GoogleMobileAds.Api;
public class GoogleAdManager : MonoBehaviour
{
public UI_Controller uiController;
public string appId = "ca-app-pub-8348036981481517~5243854015";
public string rewardedId = "ca-app-pub-8348036981481517/1997126571";
BannerView bannerView;
InterstitialAd interstitialAd;
RewardedAd rewardedAd;
private void Start()
{
MobileAds.RaiseAdEventsOnUnityMainThread = true;
MobileAds.Initialize(initStatus =>
{
print("Ads Initialised !!");
});
}
public void LoadRewardedAd()
{
if (rewardedAd != null)
{
rewardedAd.Destroy();
rewardedAd = null;
}
Debug.Log("Loading the rewarded ad.");
var adRequest = new AdRequest();
RewardedAd.Load(rewardedId, adRequest,
(RewardedAd ad, LoadAdError error) =>
{
if (error != null || ad == null)
{
Debug.LogError("Rewarded ad failed to load an ad " +
"with error : " + error);
return;
}
Debug.Log("Rewarded ad loaded with response : "
+ ad.GetResponseInfo());
rewardedAd = ad;
Debug.Log("Give " + rewardedId);
ShowRewardedAd();
});
}
public void ShowRewardedAd()
{
if (rewardedAd != null && rewardedAd.CanShowAd())
{
rewardedAd.Show((Reward reward) =>
{
print("Give reward to player !!");
GrantCoins(100);
});
}
else
{
print("Rewarded ad not ready");
}
}
public void RewardedAdEvents(RewardedAd ad)
{
ad.OnAdPaid += (AdValue adValue) =>
{
Debug.Log("Rewarded ad paid {0} {1}." +
adValue.Value +
adValue.CurrencyCode);
};
ad.OnAdImpressionRecorded += () =>
{
Debug.Log("Rewarded ad recorded an impression.");
};
ad.OnAdClicked += () =>
{
Debug.Log("Rewarded ad was clicked.");
};
ad.OnAdFullScreenContentOpened += () =>
{
Debug.Log("Rewarded ad full screen content opened.");
};
ad.OnAdFullScreenContentClosed += () =>
{
Debug.Log("Rewarded ad full screen content closed.");
};
ad.OnAdFullScreenContentFailed += (AdError error) =>
{
Debug.LogError("Rewarded ad failed to open full screen content " +
"with error : " + error);
};
}
void GrantCoins(int coins)
{
uiController.AdWatchComplete();
}
}