Asteroid avoider

Why am I having this error when I have made the gameid in dashboard and the id number is same

Hi,

In which course and lecture are you?

I tried what you said but it didn’t worked sorry for replying you late I am doing two courses the 2d one and mobile game development too

Does that mean this problem is for the mobile course? I’m asking because I’m the teaching assistent in the Unity 2D and Unity 3D courses but do not recognise this problem.

The ad isn’t running basically if I click the continue button
And I am doing unity c# mobile game development

In this case, @Brian_Trotter will hopefully be able to help you. :slight_smile:

1 Like

Looking forward to it

Hi Hamna,
It looks like the ads system hasn’t been initialized yet.
Make sure you have the latest version of Unity Ads installed in the Package Manager.
Open the Services window (Window/General/Services or Alt-0) and click on the Ads button. You may need to create a Project ID. Once you have a Project ID, you should be able to click on Ads to get to the Unity Ads website to set up your ads account and get an id for this project.

Sir I have updated the ads package and the game ids are with the same number which is on unity dashboard still I am facing the same error and warning. I checked my script and #if is in grey colour.

Is your Build Setting target set to Android? The #if UNITY_ANDROID block will be gray (not even seen by the compiler) if it is not, the #if UNITY_IOS block will be gray if the build target is not IOS.

It is build on Android but how do I select IOS together with it

You can’t. Your build target can be Android or iOS but not both (at the same time).

If you want to build to multiple platforms, you have to switch platforms between each build (Unity has to make changes to the meta data).

For example: Set Platform to Android, Build project to APK ready to upload to Play Store. Set platform to iOS, build XCode project ready to compile on a Mac with XCode.

When you set the platform, the value of #if UNITY_ANDROID and #if UNITY_IOS will be set appropriately.

I tried what you said as my targeted platform is android and I am building on it but #if is still in grey

Let’s take a look at your AdManager.cs script.
Be sure to paste in the text of the script, not a screenshot.

using System.Collections:
usnig System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;

public class AdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
    [SerializeField] private bool testMode = true;


    public static AdManager Instance;

#if UNITY_ANDROID

    private string gameId = "4716473";

#elif UNITY_IOS

    private string gameId = "4716472";    

#endif      

    private GameOverHandler gameOverHandler;
    void Awake()
   {
      if(Instance != null && Instance != this)
      {
          Destroy(gameObject);
      }
      else
      {
          Instance = this;
          DontDestroyOnLoad(gameObject);       
          Advertisement.Initialize("gameId", testMode, this);
      }
   }

   
    public void ShowAd(GameOverHandler gameOverHandler)
    {

        this.gameOverHandler = gameOverHandler;

        Advertisement.Show("rewardedVideo", this);

    }

   

    public void OnUnityAdsDidError(string message)

    {

        Debug.LogError($"Unity Ads Error: {message}");

    }

    public void OnUnityAdsDidStart(string placementId)

    {

        Debug.Log("Ad Started");

    }

    public void OnUnityAdsReady(string placementId)

    {

        Debug.Log("Unity Ads Ready");

    }

    public void OnInitializationComplete()

    {

        Debug.Log("Unity Ads initialization complete.");

    }

    public void OnInitializationFailed(UnityAdsInitializationError error, string message)

    {

        Debug.Log($"Unity Ads initialization failed: {error} - {message}");

    }

    public void OnUnityAdsAdLoaded(string placementId)

    {

        Debug.Log($"Ad loaded: {placementId}");

    }

    public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)

    {

        Debug.Log($"Error loading Ad unit {placementId}: {error} - {message}");

    }

    public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)

    {

        throw new System.NotImplementedException();

    }

    public void OnUnityAdsShowStart(string placementId)

    {

   

    }

    public void OnUnityAdsShowClick(string placementId)

    {

       

    }

    public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)

    {

       

        switch (showCompletionState)

        {

            case UnityAdsShowCompletionState.COMPLETED:

                gameOverHandler.ContinueGame();

                break;

            case UnityAdsShowCompletionState.SKIPPED:

                // Ad was skipped

                break;

            case UnityAdsShowCompletionState.UNKNOWN:

                Debug.LogWarning("Ad Failed");

                break;

        }

    }

   

}

my Advertisement package is 4.0.0

I believe this may be your issue. In Awake, you’re using a string constant “gameId” instead of the variable gameId. The Unity Ads system doesn’t recognize it so it’s sending back (rather uninformative) messages that the ads are not initialized (but not precisely why).

Advertisement.Initialize(gameId, testmode, this);
1 Like

It finally worked sir thank you so much

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms