- Home /
'IUnityAdsListener' could not be found
Full error: error CS0246: The type or namespace name 'IUnityAdsListener' could not be found (are you missing a using directive or an assembly reference?)
Unity 2019.4.17f1
Ads has been turned on
Package Manager shows Advertisement 3.5.2 installed
My C# script:
using System.Collections; using System.Collections.Generic; using UnityEngine.Advertisements; using UnityEngine;
public class AdsManager : MonoBehaviour, IUnityAdsListener {
string googlePlayID = "4055395";
string applePlayID = "4055394";
string myVideoId = "video";
string myRewardVideoId = "rewardedVideo";
string myInterstatialId = "Interstatial";
string myBannerId = "Banner";
bool isTestGameMode = false;
// Start is called before the first frame update
void Start()
{
Advertisement.AddListener (this);
Advertisement.Initialize(googlePlayID, isTestGameMode);
}
public void DisplayInterstitialAds() {
if (Advertisement.IsReady(myInterstatialId)) {
Advertisement.Show(myInterstatialId);
}
}
public void DisplayVideoAds() {
Advertisement.Show(myRewardVideoId);
}
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsDidFinish (string surfacingId, ShowResult showResult) {
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished) {
// Reward the user for watching the ad to completion.
Debug.LogWarning ("You get a reward.");
} else if (showResult == ShowResult.Skipped) {
// Do not reward the user for skipping the ad.
Debug.LogWarning ("You don't get a reward.");
} else if (showResult == ShowResult.Failed) {
Debug.LogWarning ("The ad did not finish due to an error.");
}
}
public void OnUnityAdsReady (string surfacingId) {
// If the ready Ad Unit or legacy Placement is rewarded, show the ad:
if (surfacingId == myRewardVideoId) {
// Optional actions to take when theAd Unit or legacy Placement becomes ready (for example, enable the rewarded ads button)
}
}
public void OnUnityAdsDidError (string message) {
// Log the error.
}
public void OnUnityAdsDidStart (string surfacingId) {
// Optional actions to take when the end-users triggers an ad.
}
// When the object that subscribes to ad events is destroyed, remove the listener:
public void OnDestroy() {
Advertisement.RemoveListener(this);
}
}
Answer by finneous · Oct 08, 2021 at 02:56 PM
@PolymathicIndustries, I updated Advertisement to 3.7.5 (the latest and greatest), closing and re-opening the Unity editor two of times. No joy. I get the same error:
Assets/scripts/WWIFC.cs(28,37): error CS0246: The type or namespace name 'IUnityAdsListener' could not be found (are you missing a using directive or an assembly reference?)
I am at the same Unity version: 2019.4.17f1
@finneous I noticed that on line 8 that your code is not highlighted, as though you have it, but have not implemented it. I am not sure if this is your solution, but without seeing the rest of the code I cannot really say. Is there an initialization of "Advertisement" anywhere in your code?
Answer by AirDemon · Nov 06, 2021 at 06:10 PM
I had this happen to me so I thought I would add to the thread in case anyone else comes across it. The adverts package was installed for me so I uninstalled, then re-installed and the errors went away.
Hope that's useful for someone.
Answer by PolymathicIndustries · Oct 03, 2021 at 05:01 PM
Not sure if you still need a solution, but for future viewers, this is an update issue. To resolve this head over to the package manager, select Advertisements as shown in finneous' screenshots above, except this time you need to update it. Click on Advertisements and select/click on the latest/higher number. Once up date your package to the latest version the errors in your IDE will go away, having been resolved.
Hope this helps @finneous
Your answer
Follow this Question
Related Questions
Account balance became zero 0 Answers
my app has impression more than 5K but ecpm is too low....How it increases ?? 1 Answer
Am I allowed to make money under 18 years old? 2 Answers
monetization v ads 0 Answers
How to give players "Real money"? 0 Answers