The type or namespace name 'IUnityAdsListener' could not be found

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

and also current build platform is set to android please help.

Please help me:

Here is my code:

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;

#if UNITY_ANDROID

private string gameId = "5215369";

#elif UNITY_IOS

private string gameId = "5215368";

#endif

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

}

}

Perhaps look at this; 'IUnityAdsListener' could not be found - Unity Answers

I See this link but this link not help me.
please tell me how can you do this.

Here’s another post with the same issue:

Thanks its works this is my AdManagerScript now:

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;

public class AdManagerScript : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
{
    [SerializeField] Button _showAdButton;
    [SerializeField] string _androidAdUnitId = "Rewarded_Android";
    [SerializeField] string _iOSAdUnitId = "Rewarded_iOS";

    string _adUnitId = null; // This will remain null for unsupported platforms
 
    void Awake()
    {  
        // Get the Ad Unit ID for the current platform:
#if UNITY_IOS
        _adUnitId = _iOSAdUnitId;
#elif UNITY_ANDROID
        _adUnitId = _androidAdUnitId;
#endif
        //Disable the button until the ad is ready to show:
        _showAdButton.interactable = false;
    }


    // Load content to the Ad Unit:
    public void LoadAd()
    {
        // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
        Debug.Log("Loading Ad: " + _adUnitId);
        Advertisement.Load(_adUnitId, this);
    }

 

    // If the ad successfully loads, add a listener to the button and enable it:

    public void OnUnityAdsAdLoaded(string adUnitId)
    {
        Debug.Log("Ad Loaded: " + adUnitId);
        if (adUnitId.Equals(_adUnitId))
        {
            // Configure the button to call the ShowAd() method when clicked:
            _showAdButton.onClick.AddListener(ShowAd);
            // Enable the button for users to click:
            _showAdButton.interactable = true;
        }
    }

 

    // Implement a method to execute when the user clicks the button:
    public void ShowAd()
    {
        // Disable the button:
        _showAdButton.interactable = false;
        // Then show the ad:
        Advertisement.Show(_adUnitId, this);
    }

 

    // Implement the Show Listener's OnUnityAdsShowComplete callback method to determine if the user gets a reward:
    public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
    {
        if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
        {
            Debug.Log("Unity Ads Rewarded Ad Completed");
            // Grant a reward.
            // Load another ad:
            Advertisement.Load(_adUnitId, this);
        }
    }

 

    // Implement Load and Show Listener error callbacks:
    public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
    {
        Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
        // Use the error details to determine whether to try to load another ad.
    }

 
    public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
    {
        Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
        // Use the error details to determine whether to try to load another ad.
    }

     public void OnUnityAdsShowStart(string adUnitId) { }
    public void OnUnityAdsShowClick(string adUnitId) { }

     void OnDestroy()

    {
        // Clean up the button listeners:
        _showAdButton.onClick.RemoveAllListeners();
    }
}

but Here is another error please tell me hoe to solve this error is:
Assets\Scripts\GameOverHandler.cs(33,25): error CS0117: 'AdManagerScript' does not contain a definition for 'Instance'

I don’t know. Follow the course. It says your GameOverHandler is expecting AdManagerScript to have an Instance property which it doesn’t. It must’ve been created somewhere. I don’t have the course, so I can’t help more than that

Thanks for your help.

The Instance property suggests that AdManagerScript is a singleton. Perhaps look at the ‘Implementing Ads’ lecture again

I See that lecture 100 times but nothing works.

Please help!
how to Solve this error:
Assets\Scripts\AdManagerScript.cs(29,39): error CS0103: The name ‘gameId’ does not exist in the current context

You’re referencing a gameId that does not exist.

If you’ll recall from the lessons, Nathan sets the AdManager up to be a Singleton. This is the Awake() method from the course:

    public static AdManager Instance;

    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);

            Advertisement.Initialize(gameId, testMode, this);
        }
    }

Factoring in your null string method to avoid the compile errors when the wrong platform is set (actually, you shouldn’t do this, because you really want the project configured to Android or iOS for a number of behind the scenes reasons), your Awake method will look like this:

    void Awake()
    {
        #if UNITY_ANDROID
            adUnitId = _androidAdUnitId;
        #elif UNITY_IOS
            adUnitId = _iOSAdUnitId;
        #endif
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);

            Advertisement.Initialize(gameId, testMode, this);
        }
    }

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms