Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Initializing ads gets stuck

Discussion in 'Unity Ads & User Acquisition' started by ProJVer, Jul 3, 2022.

  1. ProJVer

    ProJVer

    Joined:
    Mar 6, 2022
    Posts:
    1
    I'm trying to add avertisement to my game but I ran into an issue. When I load ads in the inspector everything works fine, but when I build the project and run it on my phone it gets stuck. It starts initializing but never completes or fails. Does anyone knows how to fix this?
    Sorry for my bad English.

    Here is my code:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
    7. {
    8.     [SerializeField] Button _showAdButton;
    9.     [SerializeField] Text _error; //this is the text object i used t display messages on build.
    10.     [SerializeField] string _androidGameId;
    11.     [SerializeField] string _iOSGameId;
    12.     [SerializeField] bool _testMode = false;
    13.     private string _gameId;
    14.     [SerializeField] AddManager addManager          ;
    15.     private int niks;
    16.     void Start()
    17.     {
    18.         InitializeAds();
    19.     }
    20.  
    21.     public void InitializeAds()
    22.     {
    23.         _error.text = "Ads initializing";
    24.         _gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
    25.             ? _iOSGameId
    26.             : _androidGameId;
    27.         Advertisement.Initialize("4818095", false, this);
    28.  
    29.     }
    30.  
    31.     public void OnInitializationComplete()
    32.     {
    33.         _error.text = "Ads initialized";
    34.         addManager.LoadAd();
    35.         _showAdButton.interactable = true;
    36.     }
    37.  
    38.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    39.     {
    40.         _error.text = $"Unity Ads Initialization Failed: {error.ToString()} - {message}";
    41.     }
    42. }
    43.