Hello there, i have an ad script that normally should show ads only at the start of the scene (every 3 times player dies) However there been few reports that ads just playing in the middle of the game, the worse the internet the more the issue occurs. here is the script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
using GoogleMobileAds.Api;
public class AdsMan : MonoBehaviour
{
private InterstitialAd Interstitial;
private int a;
IEnumerator Start()
{
Advertisement.Initialize("-------", true);
while (!Advertisement.IsReady())
{
yield return null;
}
if (PlayerPrefs.GetInt("Deaths") >= 3)
{
PlayerPrefs.SetInt("Deaths", 0);
}
else if (PlayerPrefs.GetInt("Deaths") == 2)
{
Advertisement.Show();
a = PlayerPrefs.GetInt("Deaths");
a++;
PlayerPrefs.SetInt("Deaths", a);
}
else
{
a = PlayerPrefs.GetInt("Deaths");
a++;
PlayerPrefs.SetInt("Deaths", a);
}
}
}
I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.
Doing this should help you answer these types of questions:
is this code even running? which parts are running? how often does it run?
what are the values of the variables involved? Are they initialized?
Knowing this information will help you reason about the behavior you are seeing.
For instance, just looking at the above, it only waits until an ad is ready, then plows right ahead and might show it, no further check. This seems wrong.
That may not be possible because the problem is only happening when there is real ads and as far as i know i am not legally able to run real aps in a testing enviroment.
Hmm so what you saying is i need a checker that will confirmed if the player started moving and if they did i should not show ads. I’ll give that a try.