# Unity에서 배너 광고 구현

> Unity 프로젝트 배너 광고를 구현합니다. 광고 콘텐츠를 로드하고 C# 스크립트를 통해 화면의 고정된 위치에 표시합니다.

> **Note:**
>
> 2026년 4월 1일부터 Advertisement 레거시 패키지를 통한 직접 연동을 통해 Unity Ads 수익을 창출하는 앱 광고 성과가 저하될 수 있습니다. 성과 저하를 방지하려면 입찰자로 Unity Ads 통합으로 전환하십시오.
>
> Unity Ads 네트워크는 계속해서 직접 통합을 사용하여 모든 앱 Fill을 지원하고 제공합니다. 그러나 수익과 성과를 극대화하기 위해 Unity의 광고 Mediation 플랫폼인 [LevelPlay용 Ads Mediation 패키지를 설치하는](/grow/levelplay/sdk/unity/package-integration.md.md) 것이 좋습니다.

> **Important:**
>
> [app-ads.txt](/monetization/dashboard/app-ads-txt.md)는 광고 생태계의 부정 행위를 근절하고 투명성을 창출하기 위한 [IAB](https://www.iab.com/) 이니셔티브입니다. 설명된 대로 app-ads.txt를 구현해야 합니다. 그렇지 않으면 배너 수요가 크게 줄어듭니다.

## 스크립트 구현##script-implementation

스크립트 헤더에서 `Banner` 클래스를 포함하는 `UnityEngine.Advertisements` 네임스페이스를 선언합니다. 다음으로, SDK를 초기화한 후 `Banner.Load` 및 `Banner.Show` 메서드를 사용하여 배너 광고를 로드하고 표시합니다.

다음 예제 스크립트는 씬의 버튼을 설정하여 이 기능을 테스트하는 방법을 보여 줍니다. Unity 에디터에서 버튼을 만들려면 **Game Object** > **UI** > **Button**을 선택합니다.

> **Note:**
>
> SDK가 초기화된 후에만 콘텐츠를 로드하십시오. 그렇지 않으면 스크립트가 작동하지 않습니다. 이 예제에서 초기화는 다른 스크립트에서 처리합니다.

### 배너 광고 예시##banner-ad-example

1. **C#**

   ```cs
   using UnityEngine;
   using UnityEngine.UI;
   using UnityEngine.Advertisements;

   public class BannerAdExample : MonoBehaviour
   {
     // For the purpose of this example, these buttons are for functionality testing:
     [SerializeField] Button _loadBannerButton;
     [SerializeField] Button _showBannerButton;
     [SerializeField] Button _hideBannerButton;

     [SerializeField] BannerPosition _bannerPosition = BannerPosition.BOTTOM_CENTER;

     [SerializeField] string _androidAdUnitId = "Banner_Android";
     [SerializeField] string _iOSAdUnitId = "Banner_iOS";
     string _adUnitId = null; // This will remain null for unsupported platforms.

     void Start()
     {
       // Get the Ad Unit ID for the current platform:
       #if UNITY_IOS
       _adUnitId = _iOSAdUnitId;
       #elif UNITY_ANDROID
       _adUnitId = _androidAdUnitId;
       #endif

       // Disable the button until an ad is ready to show:
       _showBannerButton.interactable = false;
       _hideBannerButton.interactable = false;

       // Set the banner position:
       Advertisement.Banner.SetPosition(_bannerPosition);

       // Configure the Load Banner button to call the LoadBanner() method when clicked:
       _loadBannerButton.onClick.AddListener(LoadBanner);
       _loadBannerButton.interactable = true;
     }

     // Implement a method to call when the Load Banner button is clicked:
     public void LoadBanner()
     {
         // Set up options to notify the SDK of load events:
         BannerLoadOptions options = new BannerLoadOptions
         {
             loadCallback = OnBannerLoaded,
             errorCallback = OnBannerError
         };

         // Load the Ad Unit with banner content:
         Advertisement.Banner.Load(_adUnitId, options);
     }

     // Implement code to execute when the loadCallback event triggers:
     void OnBannerLoaded()
     {
         Debug.Log("Banner loaded");

         // Configure the Show Banner button to call the ShowBannerAd() method when clicked:
         _showBannerButton.onClick.AddListener(ShowBannerAd);
         // Configure the Hide Banner button to call the HideBannerAd() method when clicked:
         _hideBannerButton.onClick.AddListener(HideBannerAd);

         // Enable both buttons:
         _showBannerButton.interactable = true;
         _hideBannerButton.interactable = true;     
     }

     // Implement code to execute when the load errorCallback event triggers:
     void OnBannerError(string message)
     {
         Debug.Log($"Banner Error: {message}");
         // Optionally execute additional code, such as attempting to load another ad.
     }

     // Implement a method to call when the Show Banner button is clicked:
     void ShowBannerAd()
     {
         // Set up options to notify the SDK of show events:
         BannerOptions options = new BannerOptions
         {
             clickCallback = OnBannerClicked,
             hideCallback = OnBannerHidden,
             showCallback = OnBannerShown
         };

         // Show the loaded Banner Ad Unit:
         Advertisement.Banner.Show(_adUnitId, options);
     }

     // Implement a method to call when the Hide Banner button is clicked:
     void HideBannerAd()
     {
         // Hide the banner:
         Advertisement.Banner.Hide();
     }

     void OnBannerClicked() { }
     void OnBannerShown() { }
     void OnBannerHidden() { }

     void OnDestroy()
     {
         // Clean up the listeners:
         _loadBannerButton.onClick.RemoveAllListeners();
         _showBannerButton.onClick.RemoveAllListeners();
         _hideBannerButton.onClick.RemoveAllListeners();
     }
   }
   ```

## 배너 위치##banner-position

기본적으로 배너 광고는 화면 중앙 하단에 고정되어 표시되며 320x50픽셀 또는 728x90픽셀 해상도를 지원합니다. 배너 앵커를 지정하려면 `Banner.SetPosition` API를 사용합니다. 예시:

```cs
Advertisement.Banner.SetPosition (BannerPosition.TOP_CENTER);
```

**다음 단계**: [수익화 전략](/monetization/getting-started/monetization-strategy.md) 가이드를 검토하고 [구현 내용을 테스트](/ads-unity/4.19.0/sdk-integration/test-integration.md)하십시오.
