AdManager throwing error

I am following the Asteroid Avoider course. As far as I can tell I have typed the code in exactly as the instructor did, but IUnityAdsListener is throwing this error:

The type or namespace name ‘IUnityAdsListener’ could not be found (are you missing a using directive or an assembly reference?)

I am also getting an error on

"Advertisement.Addlistener(this);

this is the code I have in AdManager.cs:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.Advertisements;

public class AdManager : MonoBehaviour, IUnityAdsListener

{

[SerializeField] private bool testMode = true;

public static AdManager Instance;

private string gameId = "5259024";

private GameOverHandler GameOverHandler;

void Awake()

{

if(Instance != null && Instance != this)

{

    Destroy(gameObject);

}

else

{

    Instance = this;

    DontDestroyOnLoad(gameObject);

    Advertisement.Addlistener(this);

    Advertisement.Initialize(gameId, testMode);

}

}

public void ShowAd(GameOverHandler gameOverHandler)

{

this.GameOverHandler = gameOverHandler;

Advertisement.Show("rewardedVideo");

}

public void OnUnityAdsDidError(string message)

{

Debug.LogError($"Unity ads Error: {message}");

}

public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)

{

switch(showResult)

{

    case ShowResult.Finished:

    GameOverHandler.ContinueGame();

        break;

    case ShowResult.Skipped:

    //ad was skipped

        break;

    case ShowResult.Failed:

    Debug.LogWarning("Ad Failed");

        break;

}

}

public void onUnityAdsDidStart(string placementId)

{

Debug.Log("Ad Started");

}

public void OnUnityAdsReady(string placementId)

{

Debug.Log("Unity Ads Ready");

}

}

See here:

Unity has changed the ads system several times. We will be updating with a full patch in the near future.

I’m at this stage also… Should I Shelve this until the course is updated?

I decided to just give it a go and just finished it. I think giving something a go on your own is a great learning challenge and come back to it when the new video has arrived.

Here is a video of the working ad. https://youtu.be/qtJDZuiGCok
“yeah nah” should give away my location in this universe.

good luck

2 Likes

Privacy & Terms