using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
using UnityEngine.SceneManagement;
public class AdManager : MonoBehaviour, IUnityAdsListener
{
string AppStore_ID = "3862326";
bool testMode = true;
string myPlacementId = "rewardedVideo";
bool runningPauseAd;
bool loadSceneOnDone;
string sceneToLoad;
public bool premiumNoAds;
// Start is called before the first frame update
void Start()
{
Advertisement.Initialize(AppStore_ID, testMode);
Advertisement.AddListener(this);
}
public void DisplayInterstitialAd()
{
if (Application.internetReachability == NetworkReachability.NotReachable)
{
//Give internet connectivity feedback here
return;
}
Advertisement.Show();
}
public void DisplayVideoAdAndPauseGame()
{
if (Application.internetReachability == NetworkReachability.NotReachable)
{
//Give internet connectivity feedback here
return;
}
print("Running Video Ad...");
Time.timeScale = 0;
runningPauseAd = true;
Advertisement.Show(myPlacementId);
}
public void DisplayVideoAdAndPauseGameAndLoadScene(string scene)
{
if (Application.internetReachability == NetworkReachability.NotReachable)
{
//Give internet connectivity feedback here
return;
}
print("Running Video Ad...");
Time.timeScale = 0;
runningPauseAd = true;
sceneToLoad = scene;
Advertisement.Show(myPlacementId);
}
public void DisplayVideoAd()
{
if (Application.internetReachability == NetworkReachability.NotReachable)
{
//Give internet connectivity feedback here
return;
}
print("Running Video Ad...");
Advertisement.Show(myPlacementId);
}
// 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.
print("Ad watched to completion");
OnAdWatched();
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad.
print("Ad skipped");
OnAdSkipped();
}
else if (showResult == ShowResult.Failed)
{
Debug.LogWarning("The ad did not finish due to an error.");
}
throw new System.NotImplementedException();
}
private void OnAdWatched()
{
if (runningPauseAd)
{
Time.timeScale = 1;
runningPauseAd = false;
}
if (loadSceneOnDone)
{
SceneManager.LoadScene(sceneToLoad);
loadSceneOnDone = false;
}
}
private void OnAdSkipped()
{
if (runningPauseAd)
{
Time.timeScale = 1;
}
if (loadSceneOnDone)
{
SceneManager.LoadScene(sceneToLoad);
}
}
void IUnityAdsListener.OnUnityAdsReady(string placementId)
{
// If the ready Placement is rewarded, show the ad:
if (placementId == myPlacementId)
{
}
}
void IUnityAdsListener.OnUnityAdsDidError(string message)
{
// Log the error.
}
void IUnityAdsListener.OnUnityAdsDidStart(string placementId)
{
// Optional actions to take when the end-users triggers an ad.
}
void OnDestroy()
{
Advertisement.RemoveListener(this);
}
}
Every time OnUnityAdsDidFinish() is called, a NotImplementedException is thrown, and the user is not rewarded for the ad. I am using the Advertisement Package (v3.4.2) through the Package Manager. Any fixes?
↧