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");
}
}