My Unity Ad works on IOS, but not on Android

Hi, I am using the same script on both IOS and Android. Unity Ad works fine on IOS, but it doesn’t show up on Android. I knew that Advertisement.isSupported, Advertisement.isInitialized and Advertisement.isReady are true. Have I missed something? Here is part of my script:

public class UnityAdControl : MonoBehaviour
{
    public string gameID;
    public bool isShowVideo;
    public bool isCheat;
    public bool disableTestMode;

    void Awake ()
    {
        if (Advertisement.isSupported)
        {
            Advertisement.allowPrecache = true;
           
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                gameID = "????"; // IOS Ad ID
            }
            else if (Application.platform == RuntimePlatform.Android)
            {
                gameID = "????"; // Android Ad ID
            }
           
            bool enableTestMode = Debug.isDebugBuild && !disableTestMode;
            Debug.Log(string.Format("Initializing Unity Ads for game ID {0} with test mode {1}...",
                                    gameID, enableTestMode ? "enabled" : "disabled"));
           
            Advertisement.Initialize(gameID, enableTestMode);
        }
    }

    void Update ()
    {
        if (isShowVideo)
        {
            string zoneID = "rewardedVideoZone";
           
            if (string.IsNullOrEmpty(zoneID))
            {
                zoneID = null;
            }
           
            ShowOptions options = new ShowOptions();
            options.pause = true;
            options.resultCallback = HandleShowResult;
           
            if (Advertisement.isReady(zoneID))
            {
                Advertisement.Show(zoneID, options);
                isShowVideo = false;
            }
            else
            {
                isShowVideo = false;
               
                if (Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    IOSNativePopUpManager.showMessage("Video Ad", "Sorry,\nthe Ad is not ready yet!"); // IOS Native Plugin
                }
                else if (Application.platform == RuntimePlatform.Android)
                {
                    AN_PoupsProxy.showMessage("Video Ad", "Sorry,\nthe Ad is not ready yet!"); // Android Native Plugin
                }
            }
        }
    }
   
    public void HandleShowResult (ShowResult result)
    {
        switch (result)
        {
        case ShowResult.Finished:
            isCheat = true;
            break;
        case ShowResult.Skipped:
            isCheat = false;
            break;
        case ShowResult.Failed:
            isCheat = false;
            break;
        }
    }
}

Hello,
Im not a pro but in my opinion, you should take Advertisement.Show(zoneID, options); out of Update function. Because maybe on runtime, after 48. line unity ads opens and isShowVideo=false not working. Maybe because it pauses games and its not update anymore. You can use option pause=false if it fits your game.
This is my opinion.

Regards,

It looks like you’re trying to show an ad once shortly after your game starts.

Is this correct?

I finally fixed the problem ~~

Salazar: Thanks for you advice, however, when I move “isShowVideo=false” to somewhere else, the message “Video Ad. Sorry, the Ad is not ready yet!” keep popping up until “Advertisement.isReady” is true.

Nikkolai: Not really, I want to show the Video Ad whenever the “isShowVideo” is true.

I found that i could not initialize the advertisement, then i double check the asset files. There are some files of Unity Ads moved to another folder (I guess they move automatically when I import some other plugins). After I moved them to the correct folder, everything is fine.

Anyway, thanks guys!

1 Like