유니티 C# 구글 애드몹 보상형 전면 광고 간단 구현 Admob 8.7.0
구글 애드몹 SDK 설치
Releases · googleads/googleads-mobile-unity
Official Unity Plugin for the Google Mobile Ads SDK - googleads/googleads-mobile-unity
github.com
구글 애드몹 홈페이지
보상형 전면 광고 | Unity | Google for Developers
이 페이지는 Cloud Translation API를 통해 번역되었습니다. 보상형 전면 광고 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. Rewarded interstitial is a type of incentivized
developers.google.com
v8.7.0 기준
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
// 리워드형 인터스티셜 광고 객체
private RewardedInterstitialAd _rewardedInterstitialAd;
// 광고 유닛 ID (플랫폼별로 다름)
#if UNITY_ANDROID
private string _adUnitId = "ca-app-pub-3940256099942544/5354046379";
#elif UNITY_IPHONE
private string _adUnitId = "ca-app-pub-3940256099942544/6978759866";
#else
private string _adUnitId = "unused";
#endif
public void Start()
{
// Google Mobile Ads SDK 초기화
MobileAds.Initialize((InitializationStatus initStatus) =>
{
// SDK 초기화가 완료된 후 호출되는 콜백
});
}
// 리워드형 인터스티셜 광고 로드
public void LoadRewardedInterstitialAd()
{
// 새로운 광고를 로드하기 전에 기존 광고를 정리
if (_rewardedInterstitialAd != null)
{
_rewardedInterstitialAd.Destroy();
_rewardedInterstitialAd = null;
}
Debug.Log("리워드형 인터스티셜 광고를 로드합니다.");
// 광고 요청 객체 생성
var adRequest = new AdRequest();
adRequest.Keywords.Add("unity-admob-sample");
// 광고 로드 요청
RewardedInterstitialAd.Load(_adUnitId, adRequest,
(RewardedInterstitialAd ad, LoadAdError error) =>
{
// 오류가 발생했는지 확인
if (error != null || ad == null)
{
Debug.LogError("리워드형 인터스티셜 광고 로드 실패, 오류: " + error);
return;
}
Debug.Log("리워드형 인터스티셜 광고 로드 성공: " + ad.GetResponseInfo());
_rewardedInterstitialAd = ad;
});
}
// 리워드형 인터스티셜 광고 표시
public void ShowRewardedInterstitialAd()
{
const string rewardMsg =
"리워드형 인터스티셜 광고로 유저가 보상을 받았습니다. 유형: {0}, 수량: {1}.";
// 광고를 표시할 수 있는지 확인
if (rewardedInterstitialAd != null && rewardedInterstitialAd.CanShowAd())
{
rewardedInterstitialAd.Show((Reward reward) =>
{
// TODO: 사용자에게 보상을 지급
Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
});
}
}
}
참고할만한 글
유니티 C# 구글 애드몹 Google Admob 보상형 광고 간단 적용법
구글 애드몹 SDK 설치 https://github.com/googleads/googleads-mobile-unity/releases Releases · googleads/googleads-mobile-unity Official Unity Plugin for the Google Mobile Ads SDK - googleads/googleads-mobile-unity github.com 구글 애드몹 홈페
parksh3641.tistory.com
유니티 C# 구글 애드몹 Google Admob 배너 광고 간단 적용법
구글 애드몹 SDK 설치 https://github.com/googleads/googleads-mobile-unity/releases Releases · googleads/googleads-mobile-unity Official Unity Plugin for the Google Mobile Ads SDK - googleads/googleads-mobile-unity github.com 구글 애드몹 홈페
parksh3641.tistory.com