I am facing a problem integrating the listeners for unity ads. i have gone through the tutorial of [this][1].
here is my codes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public interface IUnityAdsListener
{
void OnUnityAdsReady(string placementId);
void OnUnityAdsDidError(string message);
void OnUnityAdsDidStart(string placementId);
void OnUnityAdsDidFinish(string placementId, ShowResult showResult);
}
and my unityAds code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class UnityAds : MonoBehaviour, IUnityAdsListener
{
AddManager am;
string gameId = "1234567";
string myPlacementId = "rewardedVideo";
bool testMode = true;
// Initialize the Ads listener and service:
void Start()
{
Advertisement.AddListener(this);
Advertisement.Initialize(gameId, testMode);
}
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished)
{
// Reward the user for watching the ad to completion.
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad.
}
else if (showResult == ShowResult.Failed)
{
Debug.LogWarning("The ad did not finish due to an error.");
}
}
public void OnUnityAdsReady(string placementId)
{
// If the ready Placement is rewarded, show the ad:
if (placementId == myPlacementId)
{
Advertisement.Show(myPlacementId);
}
}
public void OnUnityAdsDidError(string message)
{
// Log the error.
}
public void OnUnityAdsDidStart(string placementId)
{
// Optional actions to take when the end-users triggers an ad.
}
}
i am getting error on
Advertisement.AddListener(this);
please help me solving this error. My ads were working perfectly without the listeners. but without listeners i cant track when users are rewarded or not. my sdk is 3.4.2
[1]: Unity developer integration guides