Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Game shows ads at places it shouldn't

Discussion in 'Scripting' started by oyunatarco, Aug 12, 2020.

  1. oyunatarco

    oyunatarco

    Joined:
    Jul 23, 2020
    Posts:
    18
    Hello there, i have an ad script that normally should show ads only at the start of the scene (every 3 times player dies) However there been few reports that ads just playing in the middle of the game, the worse the internet the more the issue occurs. here is the script.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5. using GoogleMobileAds.Api;
    6.  
    7. public class AdsMan : MonoBehaviour
    8. {
    9.     private InterstitialAd Interstitial;
    10.     private int a;
    11.     IEnumerator Start()
    12.     {
    13.         Advertisement.Initialize("-------", true);
    14.         while (!Advertisement.IsReady())
    15.         {
    16.             yield return null;
    17.         }
    18.  
    19.         if (PlayerPrefs.GetInt("Deaths") >= 3)
    20.         {
    21.             PlayerPrefs.SetInt("Deaths", 0);
    22.  
    23.         }
    24.         else if (PlayerPrefs.GetInt("Deaths") == 2)
    25.         {
    26.             Advertisement.Show();
    27.             a = PlayerPrefs.GetInt("Deaths");
    28.             a++;
    29.             PlayerPrefs.SetInt("Deaths", a);
    30.         }
    31.         else
    32.         {
    33.             a = PlayerPrefs.GetInt("Deaths");
    34.             a++;
    35.             PlayerPrefs.SetInt("Deaths", a);
    36.         }
    37.     }
    38. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run?
    - what are the values of the variables involved? Are they initialized?

    Knowing this information will help you reason about the behavior you are seeing.

    For instance, just looking at the above, it only waits until an ad is ready, then plows right ahead and might show it, no further check. This seems wrong.
     
  3. oyunatarco

    oyunatarco

    Joined:
    Jul 23, 2020
    Posts:
    18
    That may not be possible because the problem is only happening when there is real ads and as far as i know i am not legally able to run real aps in a testing enviroment.

    Hmm so what you saying is i need a checker that will confirmed if the player started moving and if they did i should not show ads. I'll give that a try.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Then output the last X lines to a Text object onscreen. Gotta get intel about how your game is operating!
     
  5. oyunatarco

    oyunatarco

    Joined:
    Jul 23, 2020
    Posts:
    18
    Huh, yeah that will work, its kind of a rare bug but if i can create it i will see what's going on, thanks.

    also added-
    Code (CSharp):
    1. while (gameManager.currentHeight <= 1)
    -before the script above, this hopefully will fix it but im not sure.