using UnityEngine;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour
{
public string gameID = “your_game_id_here”;
public string rewardedVideoPlacementID = “your_rewarded_video_placement_id”;
public string interstitialPlacementID = “your_interstitial_placement_id”;
public string bannerPlacementID = “your_banner_placement_id”;
private bool isRewardedAdShowing = false;
private bool isInterstitialAdShowing = false;
void Start()
{
Advertisement.Initialize(gameID, true);
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
}
public void ShowRewardedAd()
{
if (!isRewardedAdShowing)
{
isRewardedAdShowing = true;
Advertisement.Show(rewardedVideoPlacementID);
}
}
public void ShowInterstitialAd()
{
if (!isInterstitialAdShowing)
{
isInterstitialAdShowing = true;
Advertisement.Show(interstitialPlacementID);
}
}
public void ShowBannerAd()
{
Advertisement.Banner.Show(bannerPlacementID);
}
public void HideBannerAd()
{
Advertisement.Banner.Hide();
}
private void OnEnable()
{
Advertisement.AddListener(new UnityAdsListener());
}
private void OnDisable()
{
Advertisement.RemoveListener(new UnityAdsListener());
}
private class UnityAdsListener : IUnityAdsListener
{
public void OnUnityAdsReady(string placementId)
{
// Ad is ready, handle the event if needed
}
public void OnUnityAdsDidError(string message)
{
// Ad encountered an error, handle the event if needed
}
public void OnUnityAdsDidStart(string placementId)
{
// Ad has started, handle the event if needed
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
if (placementId == rewardedVideoPlacementID && isRewardedAdShowing)
{
isRewardedAdShowing = false;
if (showResult == ShowResult.Finished)
{
// The user watched the rewarded ad completely
// Implement your reward logic here
}
else if (showResult == ShowResult.Skipped)
{
// The user skipped the rewarded ad
}
else if (showResult == ShowResult.Failed)
{
// The rewarded ad failed to show
}
}
else if (placementId == interstitialPlacementID && isInterstitialAdShowing)
{
isInterstitialAdShowing = false;
if (showResult == ShowResult.Finished)
{
// The user watched the interstitial ad completely
}
else if (showResult == ShowResult.Skipped)
{
// The user skipped the interstitial ad
}
else if (showResult == ShowResult.Failed)
{
// The interstitial ad failed to show
}
}
}
}
}
The error is Assets\NewBehaviourScript.cs(58,38): error CS0246: The type or namespace name ‘IUnityAdsListener’ could not be found (are you missing a using directive or an assembly reference?)