using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Monetization;
public class AdControllor : MonoBehaviour
{
public static AdControllor instance;
string gameId = “4241399”;
public string video_ad = “video”;
public string rewardedVideo_ad = “rewardedVideo”;
public string banner_ad = “Banner”;
private void Awake()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
}
}
void Start()
{
Monetization.Initialize(gameId, false);
}
public void ShowVideo()
{
StartCoroutine(ShowAdWhenReady());
}
private IEnumerator ShowAdWhenReady()
{
while (!Monetization.IsReady(video_ad))
{
yield return new WaitForSeconds(0.25f);
}
ShowAdPlacementContent ad = null;
ad = Monetization.GetPlacementContent(video_ad) as ShowAdPlacementContent;
if (ad != null)
{
ad.Show();
}
}
public void ShowRewardedVideo()
{
StartCoroutine(WaitForVideo());
}
IEnumerator WaitForVideo()
{
while (!Monetization.IsReady(rewardedVideo_ad))
{
yield return null;
}
ShowAdPlacementContent ad = null;
ad = Monetization.GetPlacementContent(rewardedVideo_ad) as ShowAdPlacementContent;
if (ad != null)
{
ad.Show(VideoFinished);
}
}
void VideoFinished(ShowResult result)
{
if (result == ShowResult.Finished)
{
// Reward the player
DataManagement.instance.zombieMoney += 15;
}
}
public void ShowBanner()
{
StartCoroutine(WaitForBanner());
}
IEnumerator WaitForBanner()
{
while (!Monetization.IsReady(banner_ad))
{
yield return null;
}
ShowAdPlacementContent ad = null;
ad = Monetization.GetPlacementContent(banner_ad) as ShowAdPlacementContent;
if (ad != null)
{
ad.Show(BannerFinished);
}
}
void BannerFinished(ShowResult result)
{
if (result == ShowResult.Finished)
{
// Reward the player
DataManagement.instance.zombieMoney += 15;
}
}
}
7421243–908153–AdControllor.cs (2.61 KB)
