LevelPlay Ads Callbacks Part-2
Introduction
In this video, we will learn how to set up LevelPlay Ads Callbacks in your mobile game using Mobile Monetization Pro.
LevelPlay Ads - Banner & Interstitial Callback Event Example
using System.Collections;
using UnityEngine;
public class LevelPlayAdEventsExample : MonoBehaviour
{
private MobileMonetizationPro.MobileMonetizationPro_LevelPlayInitializer LevelPlayInitializer;
private void Start()
{
LevelPlayInitializer = MobileMonetizationPro.MobileMonetizationPro_LevelPlayInitializer.instance;
StartCoroutine(ShowInterstitialAutomatically());
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player") && LevelPlayInitializer != null)
{
LevelPlayInitializer.HideBannerAd();
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player") && LevelPlayInitializer != null)
{
LevelPlayInitializer.ShowBannerAd();
}
}
private IEnumerator ShowInterstitialAutomatically()
{
yield return new WaitForSeconds(10f);
if (LevelPlayInitializer != null)
{
LevelPlayInitializer.ShowInterstitial(true);
LevelPlayInitializer.ResetInterstitialAdTimer();
}
}
}
LevelPlay Ads - Rewarded Callback Event Example
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class ProgressionBar : MonoBehaviour
{
public Image fillImage; // Image component to fill
public float fillSpeed = 0.1f; // Speed at which the fill completes
public Button LoadLevelButton;
private void Start()
{
if (fillImage == null)
{
Debug.LogError("Fill Image is not assigned!");
return; // Exit if no image assigned
}
fillImage.fillAmount = 0f; // Ensure starting from 0
StartFilling(); // Start filling normally if assigned
}
private void Update()
{
if (MobileMonetizationPro.MobileMonetizationPro_LevelPlayInitializer.instance.IsRewardedAdCompleted == true)
{
// give reward
LoadLevelButton.gameObject.SetActive(true);
MobileMonetizationPro.MobileMonetizationPro_LevelPlayInitializer.instance.IsRewardedAdCompleted = false;
}
}
public void StartFilling()
{
StartCoroutine(FillProgressionBar());
}
private System.Collections.IEnumerator FillProgressionBar()
{
while (fillImage.fillAmount < 1f)
{
fillImage.fillAmount += fillSpeed * Time.deltaTime; // Increment fill amount based on time
fillImage.fillAmount = Mathf.Clamp01(fillImage.fillAmount); // Clamp to make sure it doesn't overshoot
yield return null; // Wait for next frame
}
// Fill completed
Debug.Log("Fill Completed!");
if (MobileMonetizationPro.MobileMonetizationPro_LevelPlayInitializer.instance != null)
MobileMonetizationPro.MobileMonetizationPro_LevelPlayInitializer.instance.ShowRewarded();
}
}