unity 2020 tutorial code example
Example 1: unity ads tutorial 2020
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
[RequireComponent (typeof (Button))]
public class RewardedAdsButton : MonoBehaviour, IUnityAdsListener {
#if UNITY_IOS
private string gameId = "1486551";
#elif UNITY_ANDROID
private string gameId = "1486550";
#endif
Button myButton;
public string myPlacementId = "rewardedVideo";
void Start () {
myButton = GetComponent <Button> ();
myButton.interactable = Advertisement.IsReady (myPlacementId);
if (myButton) myButton.onClick.AddListener (ShowRewardedVideo);
Advertisement.AddListener (this);
Advertisement.Initialize (gameId, true);
}
void ShowRewardedVideo () {
Advertisement.Show (myPlacementId);
}
public void OnUnityAdsReady (string placementId) {
if (placementId == myPlacementId) {
myButton.interactable = true;
}
}
public void OnUnityAdsDidFinish (string placementId, ShowResult showResult) {
if (showResult == ShowResult.Finished) {
} else if (showResult == ShowResult.Skipped) {
} else if (showResult == ShowResult.Failed) {
Debug.LogWarning (“The ad did not finish due to an error.”);
}
}
public void OnUnityAdsDidError (string message) {
}
public void OnUnityAdsDidStart (string placementId) {
}
}
Example 2: unity ads tutorial 2020
using UnityEngine;
using UnityEngine.Advertisements;
public class InterstitialAdsScript : MonoBehaviour {
#if UNITY_IOS
private string gameId = "1486551";
#elif UNITY_ANDROID
private string gameId = "1486550";
#endif
bool testMode = true;
void Start () {
Advertisement.Initialize (gameId, testMode);
Advertisement.Show ();
}
}