- Home /
 
I can't get variable to decrease by one
This is probably a very easy question to answer, but for some reason, I can't figure out what is wrong. I want my int showAd to decrease by one every time the Canvas1 is enabled. Here is code: using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds.Api;
 public class AdManager : MonoBehaviour {
 
     //public bool dead;
     public int showAd = 3;
     public InterstitialAd interstitial;
     public BannerView bannerView;
     public bool canShowInt;
 
     void Start () {
         RequestBanner ();
         RequestInterstitial ();
     }
 
     void Awake () {
         DontDestroyOnLoad (this);
     }
 
     void Update () {
         if (GameObject.Find ("Canvas1").GetComponent <Canvas> ().enabled == true) {
             canShowInt = true;
         } else {
             canShowInt = false;
         }
         if (showAd == 0) {
             showAd = 3;
         }
     }
 
 
     void ShowInterstitial () {
         if (canShowInt == true) {
             showAd = showAd - 1;
             if (showAd == 0) {
                 if (interstitial.IsLoaded ()) {
                     interstitial.Show ();
                     interstitial.Destroy ();
                 }
             }
         }
     }
 
              Answer by Akusan · Sep 08, 2017 at 09:49 PM
On your update function, you don't have anything calling
 void ShowInterstitial ()
 
               where your showAd is being decremented. Just add a condition that will call your ShowInterstitial function.
Your answer
 
             Follow this Question
Related Questions
Admob C# Script isn't running whatsoever. 0 Answers
Pass a function(float) as variable 2 Answers
How can I implement AdMob ads into a specific Unity Scene in XCode? 3 Answers
How to make a No Ads Button 0 Answers
unity app crashes when admob banner ad is requested but works fine for interstitial and video ad 0 Answers