Search Unity

Confused about using Ads from the Services window

Discussion in 'Unity Ads' started by herbie, Mar 4, 2017.

  1. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Hi,

    I am a little confused about using Ads from the Services window.
    I have set up my project as shown in https://docs.unity3d.com/Manual/SettingUpProjectServices.html.
    Then I enabled the Unity Ads service as shown in https://docs.unity3d.com/Manual/UnityAdsHowTo.html.
    But no ads are showing.

    When I attach this script for initializing using the Asset Package, it works fine.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class UnityAdsInitialize: MonoBehaviour
    6. {
    7.  
    8.     [SerializeField] private string androidGameId = "18658"; //ID for testing
    9.     [SerializeField] private string iosGameId = "18660"; //ID for testing
    10.  
    11.     [SerializeField] bool enableTestMode;
    12.  
    13.     void Start ()
    14.     {
    15.         string gameId = null;
    16.  
    17.         #if UNITY_IOS // If build platform is set to iOS...
    18.         gameId = iosGameId;
    19.         #elif UNITY_ANDROID // Else if build platform is set to Android...
    20.         gameId = androidGameId;
    21.         #endif
    22.  
    23.         if (string.IsNullOrEmpty(gameId))
    24.         { // Make sure the Game ID is set.
    25.             Debug.LogError("Failed to initialize Unity Ads. Game ID is null or empty.");
    26.         } else if (!Advertisement.isSupported)
    27.         {
    28.             Debug.LogWarning("Unable to initialize Unity Ads. Platform not supported.");
    29.         } else if (Advertisement.isInitialized)
    30.         {
    31.             Debug.Log("Unity Ads is already initialized.");
    32.         } else
    33.         {
    34.             Debug.Log(string.Format("Initialize Unity Ads using Game ID {0} with Test Mode {1}.",
    35.                 gameId, enableTestMode ? "enabled" : "disabled"));
    36.             Advertisement.Initialize(gameId, enableTestMode);
    37.         }
    38.     }
    39. }
    But the docs say that with Ads enabled through the Services window, Unity Ads will automatically be initialized when the game starts. And that the in-engine version of Unity Ads will conflict with any assets that have been imported from the Unity Ads asset package.

    Is there something that I'am doing wrong?
     
  2. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Another thing is that the ads show up as I play the game in the editor but when I make a build for my android phone no ads are showing up on my phone. Advertisement.IsReady() remains false.
    I use this script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Advertisements;
    4.  
    5. public class UnityShowAds: MonoBehaviour
    6. {
    7.     public IEnumerator ShowAds()
    8.     {
    9.         while (!Advertisement.IsReady())
    10.             yield return null;
    11.  
    12.         Advertisement.Show ();
    13.     }
    14. }
    edit:
    Now it's also working on my phone while I didn't changed anything.
     
    Last edited: Mar 4, 2017
  3. rasmus-unity

    rasmus-unity

    Unity Technologies

    Joined:
    Aug 15, 2014
    Posts:
    1,181
    Hi,

    Ok, sounds like you got it working. And as such seems you have integrated ads correctly. If you experience again that Ads are not showing on your device, please attach device log.

    /Rasmus