Hi there,
I am facing this issue while running the game :
and here are my cs files:
using UnityEngine;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
[SerializeField] private string androidGameId;
[SerializeField] private string iOSGameId;
[SerializeField] private bool testMode = true;
[SerializeField] private string androidAdUnitId;
[SerializeField] private string iOSAdUnitId;
public static AdManager instance;
private string gameId;
private string adUnitID;
private GameOverHandler gameOverHandler;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
InitializeAds();
}
}
private void InitializeAds()
{
Debug.Log("Initializing Ads");
#if UNITY_IOS
gameId = iOSGameId;
adUnitID = iOSAdUnitId;
#elif UNITY_ANDROID
gameId = androidGameId;
adUnitID = androidAdUnitId;
#endif
if (!Advertisement.isInitialized)
{
Advertisement.Initialize(gameId, testMode, this);
}
}
public void ShowAd(GameOverHandler gameOverHandlerInstance)
{
this.gameOverHandler = gameOverHandlerInstance;
Debug.Log("Trying to load an ad");
Advertisement.Load(adUnitID, this);
}
public void OnUnityAdsAdLoaded(string placementId)
{
Debug.Log("Ad successfully loaded");
Advertisement.Show(placementId, this);
}
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
{
Debug.Log($"Failed to load ad: {error} - {message}");
}
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
{
Debug.Log("Ad Show Complete Callback Triggered");
Debug.Log($"Show Completion State: {showCompletionState}");
if (placementId.Equals(adUnitID) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Ad completed, continuing the game");
gameOverHandler.ContinueGame();
}
else
{
Debug.Log($"Ad not completed: PlacementId = {placementId}, Completion State = {showCompletionState}");
}
}
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitID}: {error} - {message}");
}
public void OnUnityAdsShowStart(string placementId)
{
Debug.Log("Ad Show Started");
}
public void OnUnityAdsShowClick(string placementId)
{
Debug.Log("Ad Clicked");
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads Initialization Complete");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error} - {message}");
}
}
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class ScoreSystem : MonoBehaviour
{
[SerializeField] private TMP_Text scoreText;
[SerializeField] private float scoreMultiplier;
private bool shouldCount = true;
private float score;
void Update()
{
if (!shouldCount) { return; }
score += Time.deltaTime * scoreMultiplier;
scoreText.text = Mathf.FloorToInt(score).ToString();
}
public int EndTimer()
{
shouldCount = false;
scoreText.text = string.Empty;
return Mathf.FloorToInt(score);
}
}
Do you have any idea about what i am missing here?