Question by
muhammadhassan3 · Jul 12, 2021 at 12:18 PM ·
movementadsadvertisingservice
Real ads show only two times but fake ads show multiple times on android device
, using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_ADS using UnityEngine.Advertisements;
public class OwnAdManager : MonoBehaviour, IUnityAdsListener
{
public static OwnAdManager Instance;
[SerializeField] string AppId, BannerId, InterstitialId, VideoId;
[SerializeField] bool IsBanner = false, isInterstitial = false, IsVideo = false;
private float LastAdShowTime = 0f;
[SerializeField] float Ads_Delay_Time = 0f;
[SerializeField] bool testMode = false;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
}
void Start()
{
Advertisement.Initialize(AppId, testMode);
LoadVideoAd();
}
#region ------------------------VideoAD--------------------------
public void LoadVideoAd()
{
Advertisement.Load(VideoId);
}
public void ShowVideoAd()
{
if (!SaveData.Instance.RemoveAds && IsVideo && LastAdShowTime > Ads_Delay_Time)
{
Advertisement.AddListener(this);
// Check if UnityAds ready before calling Show method:
if (Advertisement.IsReady(VideoId))
{
Advertisement.Show(VideoId);
LastAdShowTime = 0;
Invoke(nameof(LoadVideoAd), 5f);
}
else
{
Debug.Log("Rewarded video is not ready at the moment! Please try again later!");
LoadVideoAd();
}
}
}
// Implement IUnityAdsListener interface methods:
public void OnUnityAdsDidFinish(string surfacingId, ShowResult showResult)
{
// Define conditional logic for each ad completion status:
if (showResult == ShowResult.Finished)
{
// Reward the user for watching the ad to completion.
}
else if (showResult == ShowResult.Skipped)
{
// Do not reward the user for skipping the ad.
}
else if (showResult == ShowResult.Failed)
{
Debug.LogWarning("The ad did not finish due to an error.");
}
Advertisement.RemoveListener(this);
}
public void OnUnityAdsReady(string surfacingId)
{
// If the ready Ad Unit or legacy Placement is rewarded, show the ad:
//if (surfacingId == mySurfacingId)
{
// Optional actions to take when theAd Unit or legacy Placement becomes ready (for example, enable the rewarded ads button)
}
}
public void OnUnityAdsDidError(string message)
{
// Log the error.
Advertisement.RemoveListener(this);
}
public void OnUnityAdsDidStart(string surfacingId)
{
// Optional actions to take when the end-users triggers an ad.
}
// When the object that subscribes to ad events is destroyed, remove the listener:
public void OnDestroy()
{
Advertisement.RemoveListener(this);
}
#endregion
#region -----------------BannerAD--------------------------
public void RequestMainMenuBanner()
{
if (!SaveData.Instance.RemoveAds)
{
if (Advertisement.Banner.isLoaded)
{
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
Advertisement.Banner.Show(BannerId);
}
else
{
Advertisement.Banner.Load();
}
}
}
public void HideMainMenuBanner()
{
if (!Advertisement.Banner.isLoaded)
Advertisement.Banner.Hide(false);
}
#endregion
#region ----------------InterstitialAd-------------------
public void LoadInterstitialAd()
{
Advertisement.Load(InterstitialId);
}
public void ShowInterstitialAd()
{
if (!SaveData.Instance.RemoveAds)
{
// Check if UnityAds ready before calling Show method:
if (Advertisement.IsReady(InterstitialId))
{
Advertisement.Show(InterstitialId);
// Replace mySurfacingId with the ID of the placements you wish to display as shown in your Unity Dashboard.
LoadInterstitialAd();
}
else
{
LoadInterstitialAd();
Debug.Log("Interstitial ad not ready at the moment! Please try again later!");
}
}
}
#endregion
private void Update()
{
LastAdShowTime += Time.deltaTime;
}
public void PermanentRemoveAds()
{
SaveData.Instance.RemoveAds = true;
}
}
#endif
Comment
Answer by iFFeXInc · Jul 30, 2021 at 08:54 AM
Same problem Here!! I tried everything like if the ad didn't load I try to load it again but nothing new happened!!
Your answer
![](https://koobas.hobune.stream/wayback/20220613040216im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Advertisements v4.0.0 Error: 'Advertisement' does not contain a definition for 'IsReady' 0 Answers
How do I lock down a level 0 Answers
How do I pause all game activity until unity ad ends 1 Answer
My unity adverts aren't working 0 Answers
Advertisement error when load new scene,Ads shows error when load scene 1 Answer