Search code examples
c#unity-game-engineunityads

Unity test ads aren't showing


I am working on adding unity advertisements to my android game. I am following a out dated unity tutorial by unity.

My problem is that when i want to get "unity's 2D test ads on android" they don't show up on computer or Remote 5

What is my code :

using System.Collections;
using UnityEngine;
using UnityEngine.Advertisements;

public class AdManager : MonoBehaviour
{
    IEnumerator Start()
    {
        Advertisement.Initialize("xxxxxxx", true);
        while(!Advertisement.IsReady())
            yield return null;
        Advertisement.Show();
    }
}

EDIT: By further inspection i think the fault partially might be because of the outdated video.


Solution

  • As I mentioned in a comment you'll want to remove your ID from the question and possibly request new IDs. I believe your issue is you are never calling this IEnumerator. Calling it Start does nothing as Monobehaviours expect a function of type void to be called in Unitys default execution.

    Simply call the IEnumerator

    private void Start()
    {
          Advertisement.Initialize("xxxxxxxx", false);
          StartCoroutine(StartAd());
    }
    
    private void StartAd()
    {
           while(!Advertisement.IsReady())
                yield return null;
            Advertisement.Show();
    }
    

    I would consider storing a reference to the Coroutine call so you are not ever trying to serve two ads at once, but as your example is called from Start, it will only ever get called one right now so it is not an issue.