유니티 전면 광고 적용

2025. 2. 3. 20:34·Unity

 

 

전면 광고  |  Unity  |  Google for Developers

이 페이지는 Cloud Translation API를 통해 번역되었습니다. 전면 광고 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 전면 광고는 호스트 앱의 인터페이스를 가

developers.google.com

https://developers.google.com/admob/unity/interstitial?hl=ko

위 사이트에 나와있는대로 따라하면 쉽게 전면 광고를 적용하는 방법을 알려준다

ShowInterstitialAd() 함수를 원할때 호출하면, 전면 광고를 띄울 수 있다

 

using System;
using UnityEngine;
using GoogleMobileAds.Api;

public class FullScreenAd : MonoBehaviour
{
    public string adUnitID = "ca-app-pub-3940256099942544/1033173712";

    private InterstitialAd interstitialAd;

    void Awake()
    {
        MobileAds.Initialize((InitializationStatus status) =>
            Debug.Log("AdMobInitialized"));
        LoadInterstitialAd();
    }

    private void Start()
    {
        GameManager.Instance.GameOverEvent += ShowInterstitialAd;
    }

    public void LoadInterstitialAd()
    {
        if (interstitialAd != null)
        {
            interstitialAd.Destroy();
            interstitialAd = null;
        }

        Debug.Log("Loading the interstitial ad.");

        var adRequest = new AdRequest();
        adRequest.Keywords.Add("unity-admob-sample");

        InterstitialAd.Load(adUnitID, adRequest, (InterstitialAd ad, LoadAdError error) =>
        {
            if (error != null || ad == null)
            {
                Debug.LogError($"interstitial ad failed to load an ad with error : {error}");
                return;
            }

            Debug.Log($"Interstitial ad loaded with response : {ad.GetResponseInfo()}");

            interstitialAd = ad;
            RegisterEventHandlers(interstitialAd);
        });
    }

    public void ShowInterstitialAd()
    {
        Debug.Log(interstitialAd.CanShowAd());
        
        if (interstitialAd != null && interstitialAd.CanShowAd())
        {
            Debug.Log("Showing interstitial ad.");
            interstitialAd.Show();
        }
        else
        {
            Debug.LogError("Interstitial ad is not ready yet.");
        }
    }

    private void RegisterEventHandlers(InterstitialAd ad)
    {
        // Raised when the ad is estimated to have earned money.
        ad.OnAdPaid += (AdValue adValue) =>
        {
            Debug.Log(String.Format("Interstitial ad paid {0} {1}.",
                adValue.Value,
                adValue.CurrencyCode));
        };
        // Raised when an impression is recorded for an ad.
        ad.OnAdImpressionRecorded += () => { Debug.Log("Interstitial ad recorded an impression."); };
        // Raised when a click is recorded for an ad.
        ad.OnAdClicked += () => { Debug.Log("Interstitial ad was clicked."); };
        // Raised when an ad opened full screen content.
        ad.OnAdFullScreenContentOpened += () => { Debug.Log("Interstitial ad full screen content opened."); };
        // Raised when the ad closed full screen content.
        ad.OnAdFullScreenContentClosed += () =>
        {
            Debug.Log("Interstitial ad full screen content closed.");
            LoadInterstitialAd();
        };
        // Raised when the ad failed to open full screen content.
        ad.OnAdFullScreenContentFailed += (AdError error) =>
        {
            Debug.LogError("Interstitial ad failed to open full screen content " +
                           "with error : " + error);
        };
    }
}

 

 

 

 

'Unity' 카테고리의 다른 글

[유니티] Git LFS 지정으로 날아간 파일 복구  (0) 2026.01.28
[유니티] 구글 플레이스토어 앱 업데이트 띄우는 법  (0) 2026.01.26
유니티 모바일 광고 적용할 때 참고용  (0) 2025.01.27
유니티 타이머 텍스트 흔들림  (0) 2025.01.15
[Unity 6 Challenge] 김치 런  (0) 2025.01.06
'Unity' 카테고리의 다른 글
  • [유니티] Git LFS 지정으로 날아간 파일 복구
  • [유니티] 구글 플레이스토어 앱 업데이트 띄우는 법
  • 유니티 모바일 광고 적용할 때 참고용
  • 유니티 타이머 텍스트 흔들림
하길
하길
게임 개발을 위한 나의 모든 지식의 총 집합체
  • 하길
    Until Dawn
    하길
  • 전체
    오늘
    어제
  • 글쓰기 관리
    • 분류 전체보기 (143)
      • Unreal Engine 5 (0)
      • Unity (31)
        • 3D (5)
        • 2D (7)
      • C++ (13)
      • C# (11)
      • 알고리즘 (35)
      • TIL (22)
      • 기타 (1)
      • 대장간 (12)
      • 메모 (2)
      • 게임리뷰 (0)
      • 일상 (0)
        • 챌린지 (0)
      • Article (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.1
하길
유니티 전면 광고 적용
상단으로

티스토리툴바