Programming problems. lag

I had some programming problems in unity with C #. I'm trying to request interstitial AD when I launch the game, so I can show it when the player died 5 times. The problem is that when I get to the fifth death, the announcement will not be shown. and when I try to request an ad when the level begins, it becomes lagging and still does not appear.

This is my code. Seems right.

void Update(){
    if (clicks >= 5) {
        RequestInterstitial();
        Debug.Log("Got 5 clicks");
        if (interstitial.IsLoaded()){
            Debug.Log("interstitial loaded");
            interstitial.Show();
            clicks = 0;
        }
    }
}

EDIT: After changing my code, I now get the error message:

NullReferenceException: the reference to the object is not installed in the ADS.ADMobsGameplay.Update () object instance (in Assets / Scripts / ADS / ADMobsGameplay.cs: 28)

Line 28 corresponds if (interstitial.IsLoaded()){in the following code:

void Update(){
    if (clicks >= 5) {
        Debug.Log("Got 5 clicks");
        if (interstitial.IsLoaded()){
            Debug.Log("interstitial loaded");
            interstitial.Show();
            clicks = 0;
        }else{
            RequestInterstitial();
        }
    }
}
+4
2

, NullReferenceException : , . - - - - . Debug.Log , .

+1

Interstitial . RequestInterstitial ( , ). , , , - :

int clicksRequired = 5;
int currentClicksRequired = 5;
if(clicks > currentClicksRequired){
    Debug.Log("Got 5 Clicks");
    if (interstitial.IsLoaded()){
        Debug.Log("interstitial loaded");
        interstitial.Show();
        RequestInterstitial();
        clicks = 0;
        currentClicksRequired = clicksRequired;
    }else{
        Debug.Log("interstitial not loaded, skipping to next click");
        currentClickRequired ++;
    }
}

5, , . , , , 0 . , 6- , 7- .., .

+1

Source: https://habr.com/ru/post/1613424/


All Articles