Search Unity

Can't get Unity Ads working

Discussion in 'Unity Ads & User Acquisition' started by will_brett, Nov 19, 2014.

  1. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    Hi there, Hopefully I'm not just being thick but I cant get Unity ads to work at all. Nothing comes up and Im sure i've followed all the instructions correctly.

    I imported the asset from the asset store.

    I then created this script which a button calls the function which i know is worked because debug.log is displayed in the console. (for "ID Num" I used the 5 digit game id number from the unity ads dashboard as this game is not yet published)

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3. using System.Collections;
    4.  
    5. public class AdsScript : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Awake ()
    9.     {
    10.         Advertisement.Initialize ("ID NUM", true);
    11.     }
    12.    
    13.     public void ShowAd()
    14.     {
    15.         Debug.Log ("Show Add");
    16.         if (Advertisement.isReady ())
    17.         {
    18.             Advertisement.Show();
    19.         }
    20.     }
    21. }
    Any idea what I am doing wrong? Thanks
     
  2. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    So it works the second time i click the button but not the first
     
  3. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    It could be that you're hitting the button before Unity Ads has finished initializing.

    Try updating your ShowAd method to something like this:
    Code (CSharp):
    1. public void ShowAd()
    2. {
    3.     if (Advertisement.isReady ())
    4.     {
    5.         Debug.Log ("Show ad.");
    6.         Advertisement.Show();
    7.     }
    8.     else
    9.     {
    10.         Debug.LogWarning ("Unable to show ad. Placement zone is not yet ready.");
    11.      
    12.         if (!Advertisement.isInitialized)
    13.         {
    14.             Debug.LogWarning ("Unity Ads is not yet initialized.");
    15.         }
    16.     }
    17. }
     
  4. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208