-1

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.

1 Answers1

0

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.

TEEBQNE
  • 6,104
  • 3
  • 20
  • 37
  • @KārlisKazāks You replaced the `xxxxxxxx` with your ID again right? – TEEBQNE Jul 02 '21 at 18:52
  • @KārlisKazāks Not sure which tutorial you used, but [`this`] one should be correct. As far as I can tell the code should work as it works for me on Android, PC and iOS. Your issue is most likely passing in `true` for the parameter as that is test mode. Set it to false to enable actual ads. – TEEBQNE Jul 03 '21 at 15:25