반응형
구글 애드몹 SDK 설치
- 구글 애드몹 홈페이지
- v8.7.0 기준
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class GoogleMobileAdsDemoScript: MonoBehaviour {
private RewardedInterstitialAd _rewardedInterstitialAd;
public void Start() {
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize((InitializationStatus initStatus) => {
// This callback is called once the MobileAds SDK is initialized.
});
#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 LoadRewardedInterstitialAd() {
// Clean up the old ad before loading a new one.
if (_rewardedInterstitialAd != null) {
_rewardedInterstitialAd.Destroy();
_rewardedInterstitialAd = null;
}
Debug.Log("Loading the rewarded interstitial ad.");
// create our request used to load the ad.
var adRequest = new AdRequest();
adRequest.Keywords.Add("unity-admob-sample");
// send the request to load the ad.
RewardedInterstitialAd.Load(_adUnitId, adRequest,
(RewardedInterstitialAd ad, LoadAdError error) => {
// if error is not null, the load request failed.
if (error != null || ad == null) {
Debug.LogError("rewarded interstitial ad failed to load an ad " +
"with error : " + error);
return;
}
Debug.Log("Rewarded interstitial ad loaded with response : " +
ad.GetResponseInfo());
_rewardedInterstitialAd = ad;
});
}
public void ShowRewardedInterstitialAd() {
const string rewardMsg =
"Rewarded interstitial ad rewarded the user. Type: {0}, amount: {1}.";
if (rewardedInterstitialAd != null && rewardedInterstitialAd.CanShowAd()) {
rewardedInterstitialAd.Show((Reward reward) => {
// TODO: Reward the user.
Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
});
}
}
}
참고할만한 글
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 인앱 리뷰 시스템 간단 구현 Google Play In-App Review API (0) | 2024.02.14 |
---|---|
유니티 C# 인벤토리 드래그 앤 드롭 시스템 간단 구현 Inventory Drag and Drop (0) | 2024.02.14 |
유니티 C# 카메라 자유롭게 자유시점으로 이동하기 간단 구현 (0) | 2024.02.14 |
유니티 C# 인앱결제 시스템 간단 구현 Unity IAP System (0) | 2024.02.14 |
유니티 C# 구글 애드몹 테스트 광고 id 설정 간단 구현 Google Admob Test id (0) | 2024.02.14 |
유니티 C# 구글 애드몹 네이티브 광고 간단 구현 Google Admob Native (0) | 2024.02.14 |
유니티 C# BoxCollider2D 일정 개수 이상 겹쳐있을 경우 코드 작성 (0) | 2024.02.11 |
유니티 C# 2d Navmesh 사용법 간단 구현 (0) | 2024.02.07 |
댓글