title: How to get an ad to play only every 4th time with Unity ads
body: <p>So in my Unity app, I have introduced Unity Ads and I want it to only play say every 4th time they hit replay.</p>
  
  <p><strong><em>EDIT: First I started updating the value to the log each time and noticed that it was restarting back to 0 each life, so I added static to the int <code>gamesPlayed</code>, and now it works as expected.</em></strong></p>
  
  <p>I created an int and gave it a value of 0. Each time the user hits reply the int gamesPlayed should increase by 1. Then if it's divisible by 4, it should play the app, but it doesn't work at all.</p>
  
  <p>If I swap it around, it works too often, <code>4 % gamesPlayed == 0</code>, so the code works that way, why not the other way?</p>
  
  <p>EDIT: I used <code>gamesPlayed</code> int as I figure later on I might do something with displaying how many games the player has played, so I wanted to keep track of that too.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>int gamesPlayed = 0;
  
  case "Replay":
    isRestartPressed = true;
    restart();
    playerController.currentState = playerController.playerStates.idle;
    gamesPlayed++;
    if(gamesPlayed % 4 == 0) {
      if (Advertisement.isReady ()) { Advertisement.Show ();}
    }
    
    break;</code></pre>
  </div>
  </div>
  </p>