Ads
The Ads module provides a comprehensive set of tools for managing and displaying ads in your game, including rewarded ads and interstitial ads.
Overview
The Ads module allows you to:
- Check whether rewarded or interstitial ads are available before showing buttons or prompts
- Display rewarded ads that grant players rewards for watching
- Display interstitial ads between game sessions
- Track ad lifecycle events (started, finished, error)
- Handle ad callbacks for proper game flow
In the Unity Editor, ad requests will simulate successful ad completion for testing purposes.
Enums
AdProgress
The AdProgress enum represents the current state of an ad.
Unity
public enum AdProgress
{
Started, // Ad has started playing
Finished, // Ad has finished playing
Error // An error occurred (ad unavailable, network issue, etc.)
}Methods
CheckRewardedAdAvailable
Check whether a rewarded ad can be shown (for example, to enable or disable a “Watch ad” button).
Unity
public void CheckRewardedAdAvailability()
{
PixidusSDK.Ads.CheckRewardedAdAvailable((isAvailable) => {
if (isAvailable)
{
resultText.text = "Rewarded Ad is available";
}
else
{
resultText.text = "Rewarded Ad is not available";
}
});
}Callback Parameters:
isAvailable(bool):trueif a rewarded ad can be requested,falseotherwise
RequestRewardedAd
Request and display a rewarded ad. The callback provides the ad progress and whether the user earned the reward.
Unity
PixidusSDK.Ads.RequestRewardedAd((progress, rewarded) => {
if (progress == AdProgress.Started)
{
// Ad started - pause game, mute audio, etc.
Time.timeScale = 0;
AudioListener.pause = true;
}
else if (progress == AdProgress.Finished)
{
// Ad finished - resume game
Time.timeScale = 1;
AudioListener.pause = false;
if (rewarded)
{
// User watched the full ad - grant reward!
Debug.Log("Reward granted!");
// Add coins, extra life, etc.
}
else
{
// User skipped the ad - no reward
Debug.Log("Ad skipped, no reward");
}
}
else if (progress == AdProgress.Error)
{
// Error occurred - handle gracefully
Time.timeScale = 1;
AudioListener.pause = false;
Debug.Log("Ad failed to load");
}
});Callback Parameters:
progress(AdProgress): The current state of the adrewarded(bool):trueif the user completed the ad and earned the reward,falseotherwise
CheckInterstitialAdAvailable
Check whether an interstitial ad can be shown before calling RequestInterstitialAd.
Unity
public void CheckInterstitialAdAvailability()
{
PixidusSDK.Ads.CheckInterstitialAdAvailable((isAvailable) => {
if (isAvailable)
{
resultText.text = "Interstitial Ad is available";
}
else
{
resultText.text = "Interstitial Ad is not available";
}
});
}Callback Parameters:
isAvailable(bool):trueif an interstitial ad can be requested,falseotherwise
RequestInterstitialAd
Request and display an interstitial (full-screen) ad. Use this between levels or during natural breaks in gameplay.
Unity
PixidusSDK.Ads.RequestInterstitialAd((progress) => {
if (progress == AdProgress.Started)
{
// Ad started - pause game
Time.timeScale = 0;
AudioListener.pause = true;
}
else if (progress == AdProgress.Finished)
{
// Ad finished - continue game flow
Time.timeScale = 1;
AudioListener.pause = false;
Debug.Log("Interstitial ad completed");
// Load next level, show menu, etc.
}
else if (progress == AdProgress.Error)
{
// Error occurred - continue anyway
Time.timeScale = 1;
AudioListener.pause = false;
Debug.Log("Interstitial ad failed");
// Continue game flow without ad
}
});Callback Parameters:
progress(AdProgress): The current state of the ad
Example Usage
Here’s a complete example of implementing ads in your game:
Unity
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Pixidus;
public class AdManager : MonoBehaviour
{
public Button watchAdButton;
public TMP_Text coinsText;
public int rewardAmount = 100;
private int playerCoins = 0;
private int levelCompletedCount = 0;
private void Start()
{
watchAdButton.onClick.AddListener(WatchRewardedAd);
UpdateCoinsDisplay();
}
public void WatchRewardedAd()
{
// Disable button to prevent double-clicks
watchAdButton.interactable = false;
PixidusSDK.Ads.RequestRewardedAd((progress, rewarded) => {
switch (progress)
{
case AdProgress.Started:
PauseGame();
break;
case AdProgress.Finished:
ResumeGame();
watchAdButton.interactable = true;
if (rewarded)
{
GrantReward();
}
break;
case AdProgress.Error:
ResumeGame();
watchAdButton.interactable = true;
ShowErrorMessage("Ad not available. Please try again later.");
break;
}
});
}
public void OnLevelComplete()
{
levelCompletedCount++;
// Show interstitial ad every 3 levels
if (levelCompletedCount % 3 == 0)
{
ShowInterstitialAd(() => {
LoadNextLevel();
});
}
else
{
LoadNextLevel();
}
}
private void ShowInterstitialAd(System.Action onComplete)
{
PixidusSDK.Ads.RequestInterstitialAd((progress) => {
switch (progress)
{
case AdProgress.Started:
PauseGame();
break;
case AdProgress.Finished:
case AdProgress.Error:
ResumeGame();
onComplete?.Invoke();
break;
}
});
}
private void PauseGame()
{
Time.timeScale = 0;
AudioListener.pause = true;
}
private void ResumeGame()
{
Time.timeScale = 1;
AudioListener.pause = false;
}
private void GrantReward()
{
playerCoins += rewardAmount;
UpdateCoinsDisplay();
Debug.Log($"Reward granted! +{rewardAmount} coins");
// Save coins
PixidusSDK.Data.SetInt("playerCoins", playerCoins, null);
}
private void UpdateCoinsDisplay()
{
coinsText.text = playerCoins.ToString();
}
private void ShowErrorMessage(string message)
{
Debug.Log(message);
// Show UI notification to player
}
private void LoadNextLevel()
{
Debug.Log("Loading next level...");
// SceneManager.LoadScene(nextLevelName);
}
}Best Practices
-
Pause your game - Always pause gameplay and audio when an ad starts
-
Handle all states - Always handle
Started,Finished, andErrorstates -
Don’t spam ads - Space out interstitial ads (e.g., every 3 levels) to avoid frustrating players
-
Make rewards meaningful - Rewarded ads should give valuable rewards that players want
-
Provide alternatives - Don’t block progression behind ads; make them optional bonuses
-
Disable ad buttons during playback - Prevent users from triggering multiple ad requests
Support
Need help? Our support team is here for you: