Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

woojin++

[8월21일] Google Ad Placements 본문

Unity

[8월21일] Google Ad Placements

곰바구니 2021. 8. 21. 21:22

https://developers.google.com/admob/unity/ad-placements

 

광고 게재위치 사용하기  |  Unity  |  Google Developers

이 가이드에서는 Google 모바일 광고 Unity 플러그인의 광고 게재위치 기능을 사용하여 앱을 위한 광고를 만들고 표시하는 방법을 보여줍니다. 기본 요건 Google 모바일 광고 SDK 초기화하기 광고를

developers.google.com


@ 셋팅 

Add Selected Registries 눌러준다 

배너 광고만 사용할 예정/ 사용할 광고 항목의 Auto Load Enabled 체크 

확인해보니 기본으로 테스트 광고 id 가 들어가 있다.

 


@ 장면에 Ad GameObject 추가하기 

Banner Ad라는 이름의 AdGameObject를 생성 / 'AdGameObject' 라는 이름은 사용하면 안된다고 한다.

 

Ad Placement에 My Banner Ad 를 선택 


Google 모바일 광고 SDK 초기화하기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;

public class GoogleAd : MonoBehaviour
{
    public void Start()
    {
        // Initialize the Mobile Ads SDK.
        MobileAds.Initialize((initStatus) =>
        {
            Debug.Log("광고오브젝스 인스턴스 생성 완료");
        });
    }

    public void OnBannerAdFailedToLoad(string reason)
    {
        Debug.Log("Banner ad failed to load:" + reason);
    }
}

 

로드가 실패할 시 원인은 꼭 알아야되니 셋팅해두자 


스크립트의 AdGameObject 사용하기

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds.Api;
using GoogleMobileAds.Placement;

public class BannerTestScript : MonoBehaviour
{

    BannerAdGameObject bannerAd;

    // Start is called before the first frame update
    void Start()
    {
        bannerAd = MobileAds.Instance
           .GetAd<BannerAdGameObject>("Banner Ad");

        bannerAd.LoadAd();
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

위치는 커스텀을 선택 후 offset으로 원하는 위치를 정한다. 

 

(offset 값을 구하기위해 캔버스를 생성, 이미지를 생성 후 원하는 위치를 찾을려고 했지만 위치값이 전혀 달랐다)

그래서 굳이 캔버스에 이미지를 맞출 필요는 없었고, 아래에 보면 생성된 배너 오브젝트의 이미지를 옴겨 원하는 위치값을 구한 후 커스텀 offset값을 설정하면 된다.

 


이제 Ocean Cleaner 본 프로젝트에 옴겨보겠다. 패키지가 임포트만 무사히 넘기면 될꺼 같다.