Advertisements API
를 사용하여 전체 화면 인터스티셜 광고를 표시하려면 SDK를 초기화한 다음 Load
함수를 사용하여 광고 콘텐츠를 광고 유닛으로 로드하고 Show
함수를 사용하여 광고를 표시합니다.
SDK 3.7.0 이상에서는 IUnityAdsLoadListener
및 IUnityAdsShowListener
콜백을 사용하여 광고 콘텐츠를 Load 또는 Show에 성공하거나 실패하는 경우에 대한 로직을 각각 구현할 수 있습니다.
using UnityEngine; using UnityEngine.Advertisements; public class InterstitialAdExample : MonoBehaviour, IUnityAdsLoadListener, IUnityAdsShowListener { [SerializeField] string _androidAdUnitId = "Interstitial_Android"; [SerializeField] string _iOsAdUnitId = "Interstitial_iOS"; string _adUnitId; void Awake() { // Get the Ad Unit ID for the current platform: _adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer) ? _iOsAdUnitId : _androidAdUnitId; } // Load content to the Ad Unit: public void LoadAd() { // IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script). Debug.Log("Loading Ad: " + _adUnitId); Advertisement.Load(_adUnitId, this); } // Show the loaded content in the Ad Unit: public void ShowAd() { // Note that if the ad content wasn't previously loaded, this method will fail Debug.Log("Showing Ad: " + _adUnitId); Advertisement.Show(_adUnitId, this); } // Implement Load Listener and Show Listener interface methods: public void OnUnityAdsAdLoaded(string adUnitId) { // Optionally execute code if the Ad Unit successfully loads content. } public void OnUnityAdsFailedToLoad(string _adUnitId, UnityAdsLoadError error, string message) { Debug.Log($"Error loading Ad Unit: {_adUnitId} - {error.ToString()} - {message}"); // Optionally execute code if the Ad Unit fails to load, such as attempting to try again. } public void OnUnityAdsShowFailure(string _adUnitId, UnityAdsShowError error, string message) { Debug.Log($"Error showing Ad Unit {_adUnitId}: {error.ToString()} - {message}"); // Optionally execute code if the Ad Unit fails to show, such as loading another ad. } public void OnUnityAdsShowStart(string _adUnitId) { } public void OnUnityAdsShowClick(string _adUnitId) { } public void OnUnityAdsShowComplete(string _adUnitId, UnityAdsShowCompletionState showCompletionState) { } }
다음 단계: Unity에서 보상형 광고 구현 기술 자료를 참조하여 구현 사항을 개선하십시오.