i’ve seen the course repo now and updated the classes with added codes and included this ContinueButton function as well but now when game ends and I click to continuebutton there are no ads showing up
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameOverHandler : MonoBehaviour
{
[SerializeField] private TMP_Text gameOverText;
[SerializeField] private ScoreSystem scoreSystem;
[SerializeField] private GameObject gameOverDisplay;
[SerializeField] private AsteroidSpawner asteroidSpawner;
[SerializeField] private GameObject player;
[SerializeField] private GameObject scoreUI;
[SerializeField] private Button continueButton;
public void ContinueButton()
{
AdManager.Instance.ShowAd(this);
continueButton.interactable = false;
}
public void EndGame()
{
Debug.Log("Game Over - Ending the game");
asteroidSpawner.enabled = false;
int finalScore = scoreSystem.EndTimer();
gameOverText.text = $"Your Score: {finalScore}";
gameOverDisplay.SetActive(true);
if (player != null) player.SetActive(false);
if (scoreUI != null) scoreUI.SetActive(false);
}
public void ContinueGame()
{
scoreSystem.StartTimer();
player.transform.position = Vector3.zero;
player.SetActive(true);
player.GetComponent<Rigidbody>().velocity = Vector3.zero;
asteroidSpawner.enabled = true;
gameOverDisplay.gameObject.SetActive(false);
}
public void PlayAgain()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void ReturnToMenu()
{
SceneManager.LoadScene("MainMenu");
}
}
using System.Collections;
using System.Collections.Generic;
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
{
InitialiseAds();
Instance = this;
DontDestroyOnLoad(gameObject);
}
}
private void InitialiseAds()
{
#if UNITY_IOS
gameId = iOSGameId;
adUnitId = iOSAdUnitId;
#elif UNITY_ANDROID
gameId = androidGameId;
adUnitId = androidAdUnitId;
#elif UNITY_EDITOR
gameId = androidGameId;
adUnitId = androidAdUnitId;
#endif
if (!Advertisement.isInitialized)
{
Advertisement.Initialize(gameId, testMode, this);
}
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
public void OnUnityAdsAdLoaded(string placementId)
{
Advertisement.Show(placementId, this);
}
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
}
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
}
public void OnUnityAdsShowStart(string placementId)
{
}
public void OnUnityAdsShowClick(string placementId)
{
}
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
{
if (placementId.Equals(adUnitId)
&& showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
gameOverHandler.ContinueGame();
}
}
public void ShowAd(GameOverHandler gameOverHandler)
{
this.gameOverHandler = gameOverHandler;
Advertisement.Load(adUnitId, this);
}
}
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 void StartTimer()
{
shouldCount = true;
}
public int EndTimer()
{
shouldCount = false;
scoreText.text = string.Empty;
return Mathf.FloorToInt(score);
}
}