Search Unity

Unity Ads stopped working.

Discussion in 'Unity Ads & User Acquisition' started by ruston, Jul 25, 2015.

  1. ruston

    ruston

    Joined:
    Jun 21, 2015
    Posts:
    3
    Hello folks.

    Unity Ads was working just fine on my game (on both android and the editor), but I went on to test it today and it suddenly stopped working, despite the fact that I didn't touch the code responsible for showing the ads in the first place. Can someone please help ?

    Here's the code I'm using to show the ads. Like I said, it was working just fine until today. The code is located in a script attached to a button.

    Code (CSharp):
    1. ublic class ShowAdvertisement : MonoBehaviour {
    2.  
    3.  
    4.     bool hasShown;
    5.     private Text text;
    6.     public GameObject AdText;
    7.     public bool developmentBuild;
    8.  
    9.  
    10.     void Awake(){
    11.  
    12.         hasShown = false;
    13.  
    14.         text = GetComponent<Text> ();
    15.  
    16.     }
    17.  
    18.     public void ShowAd(){
    19.  
    20.         if (!hasShown) {
    21.  
    22.             if (Advertisement.isSupported) {
    23.  
    24.                 Advertisement.allowPrecache = true;
    25.                 Advertisement.Initialize ("49044", developmentBuild);
    26.  
    27.             }
    28.  
    29.             Advertisement.Show (null, new ShowOptions{pause = true, resultCallback = result =>{}});
    30.  
    31.             hasShown = true;
    32.  
    33.             transform.GetChild(0).GetComponent<Text>().text = "You Watched the Ad";
    34.  
    35.             GameController.control.AddMoney(20);
    36.  
    37.             AdText.GetComponent<PlayerMoneyDisplay>().initMoney = GameController.control.currentMoney;
    38.  
    39.         } else {
    40.  
    41.             transform.GetChild(0).GetComponent<Text>().text = "You Watched the Ad";
    42.  
    43.         }
    44.     }
    45.     // Use this for initialization
    46.  
    47.  
    48. }
     
    Last edited: Jul 25, 2015
  2. ruston

    ruston

    Joined:
    Jun 21, 2015
    Posts:
    3
    I also get the following Debug.Log when I click the button to watch the ad.


    Debug: UnityEditor: init(), gameId=57478, testModeEnabled=True, gameObjectName=UnityAdsPluginBridgeObject
    UnityEngine.Advertisements.Advertisement:Initialize(String, Boolean)
    ShowAdvertisement:ShowAd() (at Assets/ShowAdvertisement.cs:30)
    UnityEngine.EventSystems.EventSystem:Update()


    Debug: onFetchCompleted
    UnityEngine.Advertisements.<getAdPlan>c__Iterator0:MoveNext()
     
    Last edited: Jul 25, 2015
  3. ullatussimo

    ullatussimo

    Unity Technologies

    Joined:
    Jun 16, 2015
    Posts:
    108
    Hello @ruston,

    Thanks for reaching out!

    You should Initialize Unity Ads when starting your game, not when you're first trying to watch them. This is because the SDK needs some time (usually not much) to pull some ads for your users to view. I also recommend that you check if Advertisement.IsReady() before trying to show an Ad, just to be sure that you actually have ads to show.

    Are you sure this is the only place where you call Advertisement code? The Debug.Log would indicate that for some reason it's calling Initialize with a different GameID from what's stated in your code.

    Hope this helps!

    Cheers,
    Simo