Unity ads(interstitial and Rewarded) show only once every game session ,Unity Ads showing interstitial and rewarded once per game session while it shows multiple times in test ads!!
Hey guys, I have a problem with Unity ads!! Everything seems to be working while testing ads on my phone but after I published my game on Google play , interstitial ads and rewarded ones stopped showing like before!! Interstitial ads should pop up every 1 minute and rewarded ones are assigned to a button but the problem is they show up only once in the game session and they suddenly stop showing !! Here is my Admanager Script:
public class AdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
//GAME
[SerializeField] string _androidGameId;
[SerializeField] string _iOsGameId;
[SerializeField] bool _testMode = false;
[SerializeField] bool _enablePerPlacementMode = true;
private string _gameId;
//Inter
[SerializeField] string _androidAdUnitId = "Interstitial_Android";
[SerializeField] string _iOsAdUnitId = "Interstitial_iOS";
string _adUnitId;
//Banner
[SerializeField] BannerPosition _bannerPosition = BannerPosition.TOP_LEFT;
[SerializeField] string _androidBannerUnitId = "Banner_Android";
[SerializeField] string _iOsBannerUnitId = "Banner_iOS";
string BannerUnitId;
//Rewarded
[SerializeField] string _androidrewardUnitId = "Rewarded_Android";
[SerializeField] string _iOsrewardUnitId = "Rewarded_iOS";
string rewardUnitId;
public int showretime=0, showinttime=0, loadinttime=0, loadretime=0;
public float intercounter = 120f;
public float rewardedcounter = 120f;
public bool Rewardok = false;
void Awake()
{
DontDestroyOnLoad(gameObject);
//
InitializeAds();
LoadBanner();
//
// Get the Ad Inter Unit ID for the current platform:
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsAdUnitId
: _androidAdUnitId;
// Get the Banner Unit ID for the current platform:
BannerUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsBannerUnitId
: _androidBannerUnitId;
// Get the Rewarded Ad Unit ID for the current platform:
rewardUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsrewardUnitId
: _androidrewardUnitId;
}
void Start()
{
// Set the banner position:
Advertisement.Banner.SetPosition(_bannerPosition);
// Configure the Load Banner button to call the LoadBanner() method when clicked:
ShowBannerAd();
LoadAd();
LoadRewardAd();
}
void Update()
{
intercounter += Time.deltaTime;
rewardedcounter += Time.deltaTime;
if (FindObjectOfType<Player>()){ if (FindObjectOfType<Player>().playad == true && intercounter >= 60f) { ShowAd(); intercounter = 0f; FindObjectOfType<Player>().playad = false; } }
}
public void InitializeAds()
{
_gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsGameId
: _androidGameId;
Advertisement.Initialize(_gameId, _testMode, _enablePerPlacementMode, this);
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
// Load content to the Ad Unit:
public void LoadAd()
{
// IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
Debug.Log("Loading Ad: " + _adUnitId);
Advertisement.Load(_adUnitId, this);
}
// Show the loaded content in the Ad Unit:
public void ShowAd()
{
LoadAd();
// Note that if the ad content wasn't previously loaded, this method will fail
Debug.Log("Showing Ad: " + _adUnitId);
Advertisement.Show(_adUnitId, this);
}
// Implement Load Listener and Show Listener interface methods:
public void OnUnityAdsAdLoaded(string adUnitId)
{
// Optionally execute code if the Ad Unit successfully loads content.
if (adUnitId.Equals(rewardUnitId))
{ loadretime = 0; }
if (adUnitId.Equals(_adUnitId)) { loadinttime = 0; }
}
public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit: {adUnitId} - {error.ToString()} - {message}");
// Optionally execite code if the Ad Unit fails to load, such as attempting to try again.
if (adUnitId.Equals(rewardUnitId))
{
if (loadretime < 3) { StartCoroutine(LoadRewardAgain()); }
}
if (adUnitId.Equals(_adUnitId))
{
if (loadinttime < 3) { StartCoroutine(LoadAdAgain()); }
}
}
public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
// Optionally execite code if the Ad Unit fails to show, such as loading another ad.
if (adUnitId.Equals(rewardUnitId))
{
if (showretime < 3) {StartCoroutine(ShowRewardAgain()); }
}
if (adUnitId.Equals(_adUnitId))
{
if (showinttime < 3) { StartCoroutine(ShowAdAgain()); }
}
}
public void OnUnityAdsShowStart(string adUnitId) {
if (adUnitId.Equals(rewardUnitId))
{ showretime = 0; }
if (adUnitId.Equals(_adUnitId)) { showinttime = 0; }
}
public void OnUnityAdsShowClick(string adUnitId) { }
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState) {
if (adUnitId.Equals(rewardUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
Rewardok = true;
// Load another ad:
Advertisement.Load(rewardUnitId, this);
}
}
// Implement a method to call when the Load Banner button is clicked:
public void LoadBanner()
{
// Set up options to notify the SDK of load events:
BannerLoadOptions options = new BannerLoadOptions
{
loadCallback = OnBannerLoaded,
errorCallback = OnBannerError
};
// Load the Ad Unit with banner content:
Advertisement.Banner.Load(BannerUnitId, options);
}
// Implement code to execute when the loadCallback event triggers:
void OnBannerLoaded()
{
Debug.Log("Banner loaded");
}
// Implement code to execute when the load errorCallback event triggers:
void OnBannerError(string message)
{
Debug.Log($"Banner Error: {message}");
// Optionally execute additional code, such as attempting to load another ad.
LoadBanner();
}
// Implement a method to call when the Show Banner button is clicked:
void ShowBannerAd()
{
// Set up options to notify the SDK of show events:
BannerOptions options = new BannerOptions
{
clickCallback = OnBannerClicked,
hideCallback = OnBannerHidden,
showCallback = OnBannerShown
};
// Show the loaded Banner Ad Unit:
Advertisement.Banner.Show(_adUnitId, options);
}
// Implement a method to call when the Hide Banner button is clicked:
void HideBannerAd()
{
// Hide the banner:
Advertisement.Banner.Hide();
}
void OnBannerClicked() { }
void OnBannerShown() { }
void OnBannerHidden() { }
public void LoadRewardAd()
{
// IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
Debug.Log("Loading Ad: " + rewardUnitId);
Advertisement.Load(rewardUnitId, this);
}
public void ShowRewardAd()
{
if(rewardedcounter >= 60f)
{
LoadRewardAd();
// Then show the ad:
Advertisement.Show(rewardUnitId, this);
rewardedcounter = 0;
}
}
IEnumerator LoadAdAgain()
{
yield return new WaitForSeconds(2f);
LoadAd();
loadinttime++;
}
IEnumerator LoadRewardAgain()
{
yield return new WaitForSeconds(2f);
LoadRewardAd();
loadretime++;
}
IEnumerator ShowAdAgain()
{
yield return new WaitForSeconds(2f);
LoadAd();
ShowAd();
showinttime++;
}
IEnumerator ShowRewardAgain()
{
yield return new WaitForSeconds(2f);
LoadRewardAd();
ShowRewardAgain();
showretime++;
}
}
Comment
Your answer
Follow this Question
Related Questions
Can Unity Ads service work without Google play services on Android? 0 Answers
Exception: Field currentActivity or type signature not found 0 Answers
How much money I can earn with Unity Ads? 1 Answer
Unity ADS doubts 0 Answers
Is Unity Ads generating revenues when Unity Analytics is disabled ? 0 Answers