How I can count how many time gameOver scene is loaded ?
I'm building a game and I want to add an interstitial ads to it, but I want it to appear after the player lost every 3 times. So when the player loses for the first time the ads will appear, and when he loses for the second and third time, nothing appears until he lost for fourth time.
Answer by Statement · Oct 31, 2015 at 11:59 PM
You could just make a static variable to keep track of how many times you've died.
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
static int timesDied; // Information is kept between level loads
void Start()
{
Die(); // "ADVERTISEMENT: sham poo"
Die(); // "ad free death"
Die(); // "ad free death"
Die(); // "ADVERTISEMENT: sham poo"
}
public void Die()
{
if (timesDied++ % 3 == 0) // Left hand side will be 0, 1, 2, 0, 1, 2 etc
DisplayAds();
else
print("ad free death");
}
void DisplayAds()
{
print("ADVERTISEMENT: sham poo");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612043447im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to assign Instantiated object through script? 1 Answer
Measuring/finding the height of a stack of game objects then recording that number. 2 Answers
How would i change my mouse cursor in between scenes 0 Answers
Picked up items being added multiple times on the inventory list. 1 Answer
Switching items - can't detect a crazy loop that is happening. 1 Answer