Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class Addmanager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener,IUnityAdsShowListener
{
[SerializeField] private bool testMode = true;
private string gameId = "4819927";
public static Addmanager Instance;
private GameOVerHandler gameOVerHandler;
private void Awake()
{
if(Instance != null && Instance != this)
{
Destroy(gameObject);
}
else
{
Instance = this;
DontDestroyOnLoad(gameObject);
Advertisement.Initialize(gameId, testMode, this);
}
}
public void ShowAdd(GameOVerHandler gameOVerHandler)
{
this.gameOVerHandler = gameOVerHandler;
Advertisement.Show("rewardedVideo", this);
}
public void OnInitializationComplete()
{
Debug.Log("int complete");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log("int failed");
}
public void OnUnityAdsAdLoaded(string placementId)
{
Debug.Log("ad loaded");
}
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit {placementId}: {error} - {message}");
}
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {placementId}: {error} - {message}");
}
public void OnUnityAdsShowStart(string placementId)
{
Debug.Log("ad show start");
}
public void OnUnityAdsShowClick(string placementId)
{
Debug.Log("ad show click");
}
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState unityAdsShowCompletionState)
{
switch ( unityAdsShowCompletionState)
{
case UnityAdsShowCompletionState.COMPLETED:
gameOVerHandler.ContinueGame();
break;
case UnityAdsShowCompletionState.SKIPPED:
break;
case UnityAdsShowCompletionState.UNKNOWN:
Debug.LogWarning("Add Failed");
break;
}
}
}