unity ads implementation tutorial 2020 code example
Example: unity ads tutorial 2020
using System.Collections;
using UnityEngine;
using UnityEngine.Advertisements;
public class BannerAdScript : MonoBehaviour {
#if UNITY_IOS
private string gameId = "1486551";
#elif UNITY_ANDROID
private string gameId = "1486550";
#endif
public string placementId = "bannerPlacement";
public bool testMode = true;
void Start () {
Advertisement.Initialize (gameId, testMode);
StartCoroutine (ShowBannerWhenReady ());
Advertisement.Banner.SetPosition (BannerPosition.TOP_CENTER);
}
IEnumerator ShowBannerWhenReady () {
while (!Advertisement.IsReady (placementId)) {
yield return new WaitForSeconds (0.5f);
}
Advertisement.Banner.Show (placementId);
}
}