In my current Unity program I wanted to implement ads. The ads do work in the Unity editor when I run the game, but when I try to run the ads on my iPhone 7 or iPad Air, there are no ads showing up. Does someone know what I am doing wrong?
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Advertisements;
public class GameManager : MonoBehaviour
{
void Start()
{
Advertisement.Initialize("Appstore-id");
}
bool gameHasEnded = false;
public float restartDelay = 1f;
public float addDelay = 1f;
public GameObject completeLevelUI;
public void CompleteLevel ()
{
completeLevelUI.SetActive(true);
Invoke("ShowAdd", addDelay);
}
public void EndGame()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("Game over");
Invoke("Restart", restartDelay);
}
}
public void ShowAdd()
{
if (Advertisement.IsReady())
{
Advertisement.Show ();
}
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
I had the same problem and the way I fixed it was a recursive function until the ad was ready. Something like:
IEnumerator ShowAd()
{
yield return new waitForSeconds(1);
if (Advertisement.IsReady())
{
Advertisement.Show ();
}
else { StartCoroutine(ShowAd()); }
}
This way it will call the method until the ad is ready to show. Also, make sure you have test (or debug) mode enabled on Unity Ads Settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With