In mobile ads are not working

In Editor everything are work but in mobile ads are not working

Please help

Anyone here to help me.

No One want to help.

Have you tried turning it off and on again?

yes.but nothing works

Your ads are working in mobile

Hi Mamona,

I am sorry you are having difficulties but you do have to allow a bit more of a reasonable timeframe for our teaching assistants to be able to respond.
We typically respond within 24-36 hours.
If you would like to get more interactive help from other students then i advise joining the community discord server whilst you wait for a TA to respond.

Brian will need more information on exactly what is not working posted here so he can see it.

Unfortunately i have not kept up with the unity mobile ads so at present i am unable to advise.

I thank-you in advance for your patience and understanding

1 Like

Hi Mamona.
Are you saying that you are getting the test ads when playing in the editor, but the ads are not showing up when building the game to Android and iOS?

Paste in your current Ad handling script, and we’ll take a look.

Thanks. I am happy that you response.

Here is my script:

using UnityEngine;
using UnityEngine.Advertisements;

public class AdManagerScript : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
    [SerializeField] private bool testMode = true;
    public static AdManagerScript Instance;
#if UNITY_ANDROID
    private string gameId = "5215925";
#elif UNITY_IOS
    private string gameId = "5215924";
#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 OnInitializationComplete()
    {
          Advertisement.Load("rewardedVideo", this);
    }

    public void OnInitializationFailed(UnityAdsInitializationError error, string message)
    {
        Debug.Log($"Unity Ads Initialization Failed: {error} - {message}");
    }

    public void ShowAd(GameOverHandler gameOverHandler)
    {
        this.gameOverHandler = gameOverHandler;
        Advertisement.Show("rewardedVideo", this);
    }

    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)
    {
        Debug.Log($"Error showing Ad Unit {placementId}: {error} - {message}");
    }

    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;
           
        }
    }
}

This code looks right, except that with recent changes to the Ad system, you need to Load() another ad every time you use an ad. You’re loading an ad when the Initilialization is complete, but not after. The easiest place to do that is in OnUnityShowAdsComplete(). I make the first line

Advertisement.Load("rewardedVideo", this);

One trouble with ads that wasn’t mentioned in the course is that there are often times when an ad simply isn’t available, either it’s not loaded yet, or at that point in time the ad broker simply doesn’t have an ad ready for you.

To help with that, it’s a good idea to ad a boolean to track whether you have an ad loaded or not.

bool adIsLoaded = false;
public bool  AdIsLoaded => adIsLoaded;

Then in OnUnityAdsLoaded, add the line

adIsLoaded=true;

and in ShowAd, add

if(!adIsLoaded) 
{
     Debug.Log("No ad is Loaded");
     return;
}
adIsLoaded = false;
//The rest of the method
1 Like

Hi! Please add this code in my code. please.

No.I have a lot of work to do i am creating a game in unreal engine. i have a lot of project. so i have no time today.

Personal attacks are not welcome in our community.

You will learn a lot more from this if you make the edits. I’ve given the exact locations to put the code patches in.

He also attack sir.

The comment was directed at both of you.

Sorry

1 Like

Sir i put the code that you say:
Now This is my code:

using UnityEngine;

using UnityEngine.Advertisements;

public class AdManagerScript : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener

{

[SerializeField] private bool testMode = true;

public static AdManagerScript Instance;

#if UNITY_ANDROID

private string gameId = "5215925";

#elif UNITY_IOS

private string gameId = "5215924";

#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 OnInitializationComplete()

{

      Advertisement.Load("rewardedVideo", this);

}

public void OnInitializationFailed(UnityAdsInitializationError error, string message)

{

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

}

public void ShowAd(GameOverHandler gameOverHandler)

{

    this.gameOverHandler = gameOverHandler;

    Advertisement.Show("rewardedVideo", this);

}

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)

{

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

}

public void OnUnityAdsShowStart(string placementId) { }

public void OnUnityAdsShowClick(string placementId) { }

public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)

{

    switch (showCompletionState)

    {

        case UnityAdsShowCompletionState.COMPLETED:

            gameOverHandler.ContinueGame();

             Advertisement.Load("rewardedVideo", this);

            break;

        case UnityAdsShowCompletionState.SKIPPED:

          Advertisement.Load("rewardedVideo", this);

            // Ad was skipped

            break;

        case UnityAdsShowCompletionState.UNKNOWN:

            Debug.LogWarning("Ad Failed");

            Advertisement.Load("rewardedVideo", this);

            break;

           

    }

}

}

Please tell me its okay

1 Like

Thanks sir you solve my problem.
But i have one more issue in-app-purchases are not work in mobile.

1 Like

Privacy & Terms