Search Unity

Unity Ads Not Showing?

Discussion in 'Scripting' started by ExbowFTW, Aug 30, 2015.

  1. ExbowFTW

    ExbowFTW

    Joined:
    May 2, 2015
    Posts:
    281
    The Unity Ads are not working/showing. These are snippets of code from my C# script:
    (AdCounter increases each time the player dies. After 3 deaths, I want it to play the ad)

    Code (csharp):
    1.  
    2. usingUnityEngine.Advertisements;
    3.  
    Code (csharp):
    1.  
    2. voidAwake () {
    3. if (Advertisement.isSupported) {
    4. Advertisement.Initialize ("MyCode"); //In my script I put the actual ID.
    5.  } else {
    6. Debug.LogWarning("Platform not supported!");
    7. Debug.Log("Platform not supported!");
    8.  }
    9.  }
    10.  
    Code (csharp):
    1.  
    2. PlayerPrefs.SetInt ("AdCounter", PlayerPrefs.GetInt ("AdCounter") + 1);
    3.  
    4. if (PlayerPrefs.GetInt ("AdCounter") > 2) {
    5. if (Advertisement.IsReady()){
    6. Advertisement.Show ();
    7.  }
    8. PlayerPrefs.SetInt ("AdCounter", 0);
    9.  }
    10.  
    What am I doing wrong? I followed both a tutorial and a little flyer that Unity gives in the Asset bundle of Unity Ads (from the Asset Store).

    Thanks,
    Exbow
     
  2. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    Do you set AdCounter to an initial value somewhere?
    Did you try to print the value of AdCounter?
    Is if (Advertisement.IsReady()) true at some point at all?
     
  3. ExbowFTW

    ExbowFTW

    Joined:
    May 2, 2015
    Posts:
    281
    I'm not sure what Advertisement.IsReady really is. I was hoping someone could explain it to me, and tell me when it sets itself to "True". Yes, the value of AdCounter is working like it's supposed to. However, Advertisement.IsReady never sets to true. I'm not sure why, and how I can make it turn true.
     
  4. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    Advertisement.IsReady shows that Advertisement.Initialize is finished and that there are ads ready to be shown.
    If Advertisement.IsReady never wents to True there's probably something wrong with the initialization process. Are you 100% sure that you're using the correct Game ID shown in the Unity ads web front end?
    You could try to move Advertisement.Initialize ("MyCode"); from Awake() to Start().

    [e]
    I do assume that you've checked that if (Advertisement.isSupported) is true. If not, please check.
     
    Last edited: Aug 30, 2015
  5. ExbowFTW

    ExbowFTW

    Joined:
    May 2, 2015
    Posts:
    281
    Hmm... Somehow, when I run it on Unity Remote 4, it works. So I guess it works, but on the Editor it doesn't. I'm not sure why. Yep I checked if it was Supported (look at the first post).

    Anyways, I think I got it figured out for now. Thanks! BTW, do you know how I actually receive money from the Unity Ads thing? Does it input money into my Unity Ads account? And if it does, how do I get that money?