Right now the game shows ads each and every time the player dies. I want the ads to appear after the third death of the player. Please guide me as I am a beginner with no real knowledge of coding. Please also specify if I need to attach the script to a specific game object.
I have put the ads code below. Thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject gameOverCanvas;
public GameObject Interstitial;
public int DeathCount = 0;
private void Start()
{
Time.timeScale = 1;
}
public void GameOver()
{
gameOverCanvas.SetActive(true);
Time.timeScale = 0;
DeathCount++;
}
private bool DeathCountCheck()
{
if (DeathCount == 3)
{
// Reset the variable, otherwise it will increase indefinitely and the condition will not be met in the future
Interstitial.GetComponent<InterstitialAds>().ShowInterstitial();
DeathCount = 0;
return true;
}
return false;
}
public void Replay()
{
SceneManager.LoadScene(0);
}