Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Ads are making me want to quit Unity

Discussion in 'Unity Ads & User Acquisition' started by Loading7088, May 20, 2023.

  1. Loading7088

    Loading7088

    Joined:
    May 5, 2023
    Posts:
    9
    Okay, so I've looked up tutorial after tutorial, and the Unity docs, and other forums, I even tried Chat GPT. My ads are not showing, and I do not understand why. I have a script that Initilizes the ads, and a script to show the ads every 5 levels (scene loads in this case.)

    Initilizer:
    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
    7. {
    8.     [SerializeField] string _androidGameId;
    9.     [SerializeField] string _iOSGameId;
    10.     [SerializeField] bool _testMode = true;
    11.     private string _gameId;
    12.  
    13.     void Awake()
    14.     {
    15.         InitializeAds();
    16.     }
    17.  
    18.     public void InitializeAds()
    19.     {
    20. #if UNITY_IOS
    21.             _gameId = _iOSGameId;
    22. #elif UNITY_ANDROID
    23.             _gameId = _androidGameId;
    24. #elif UNITY_EDITOR
    25.         _gameId = _androidGameId; //Only for testing the functionality in the Editor
    26. #endif
    27.         if (!Advertisement.isInitialized && Advertisement.isSupported)
    28.         {
    29.             Advertisement.Initialize(_gameId, _testMode, this);
    30.         }
    31.     }
    32.  
    33.  
    34.     public void OnInitializationComplete()
    35.     {
    36.         Debug.Log("Unity Ads initialization complete.");
    37.     }
    38.  
    39.     public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    40.     {
    41.         Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
    42.     }
    43. }

    and then to show the ads:
    Code (csharp):
    1.  using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class Interstitialads : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener
    7. {
    8.     [SerializeField] string _androidAdUnitId = "Interstitial_Android";
    9.     [SerializeField] string _iOsAdUnitId = "Interstitial_iOS";
    10.     string _adUnitId;
    11.  
    12.  
    13.     static int loadCount = 0;
    14.  
    15.     void Start()
    16.     {
    17.         if (loadCount == 5)
    18.         {
    19.             loadCount = 0;
    20.             ShowAd();
    21.         }
    22.         else
    23.         {
    24.             loadCount += 1;
    25.         }
    26.        
    27.     }
    28.  
    29.     public void ShowAd()
    30.     {
    31.         Advertisement.Show(_adUnitId, this);
    32.     }
    33.  
    34.  
    35.  
    36.     void Awake()
    37.     {
    38.         // Get the Ad Unit ID for the current platform:
    39.         _adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
    40.             ? _iOsAdUnitId
    41.             : _androidAdUnitId;
    42.  
    43.         LoadAd();
    44.     }
    45.  
    46.     // Load content to the Ad Unit:
    47.     public void LoadAd()
    48.     {
    49.         // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
    50.         Debug.Log("Loading Ad: " + _adUnitId);
    51.         Advertisement.Load(_adUnitId, this);
    52.     }
    53.  
    54.     // Show the loaded content in the Ad Unit:
    55.  
    56.     public void OnUnityAdsAdLoaded(string placementId)
    57.     {
    58.        
    59.     }
    60.  
    61.     public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
    62.     {
    63.        
    64.     }
    65.  
    66.     public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
    67.     {
    68.  
    69.     }
    70.     public void OnUnityAdsShowStart(string placementId)
    71.     {
    72.        
    73.     }
    74.  
    75.     public void OnUnityAdsShowClick(string placementId)
    76.     {
    77.        
    78.     }
    79.  
    80.     public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
    81.     {
    82.        
    83.     }
    84. }
     
  2. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    592
    The Start method will only be executed once, so the count will not meet the condition, maybe you can try to count in OnEnable.