I have created a sample project which shows an ad on clicking on a button.
This works fine in the editor but when I do build and run on an android device then ads are not showing on the android device.
Here is my sample code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class Ads : MonoBehaviour, IUnityAdsListener
{
public static string interstitialAd = "video";
public static string rewardedAd = "rewardedVideo";
public static string bannerAd = "banner";
private string playstoreId = "3890871";
private string applerStoreId = "3890870";
public bool testMode = true;
// Start is called before the first frame update
void Start()
{
init();
Advertisement.AddListener(this);
}
private void init()
{
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
Debug.Log("iOS Ad Initilizing");
Advertisement.Initialize(applerStoreId, testMode);
}
else
{
Debug.Log("Android Ad Initilizing");
Advertisement.Initialize(playstoreId, testMode);
}
}
// Update is called once per frame
void Update()
{
}
public void showRewarededAd()
{
Debug.Log(">>>>>>>>>>>>>>");
StartCoroutine(showAdd());
//Advertisement.Show(rewardedAd);
}
public IEnumerator showAdd()
{
while (!Advertisement.IsReady(rewardedAd))
{
Debug.Log("Ad is not ready yet");
//init();
yield return new WaitForSeconds(1);
}
Advertisement.Show(rewardedAd);
}
public void OnUnityAdsReady(string placementId)
{
Debug.Log("OnUnityAdsReady>> " + placementId);
}
public void OnUnityAdsDidError(string message)
{
Debug.Log("OnUnityAdsDidError>> " + message);
}
public void OnUnityAdsDidStart(string placementId)
{
Debug.Log("OnUnityAdsDidStart>> " + placementId);
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
Debug.Log("OnUnityAdsDidFinish>> " + placementId + ", showResult = " + showResult);
}
}
Advertisement.IsReady(rewardedAd) is always false in android device.
↧