박민혁의 개발
유니티 구글 모브앱 넣기 본문
https://geukggom.tistory.com/147
[Unity] 유니티 구글 애드몹 광고 넣는 법(Google AdMob)
애드몹을 이용해 만들어둔 게임에 광고를 넣어보겠습니다. 절차는 다음과 같습니다. 1. 구글 애드몹 가입 2. 구글 애드몹에 광고 등록 3. Unity plugin을 다운받은 후, 프로젝트에 Import 4. 광고 코드
geukggom.tistory.com
https://geukggom.tistory.com/146
[Unity] Unable to find java in the system path 오류 해결 방법
유니티를 이용하던 도중 위와 같은 문제가 생겼습니다. 자바를 설치한 적 없기 때문에 생기는 문제인데요, JDK의 경로를 JAVA_HOME 으로 추가해주면 됩니다. 1. 본인의 유니티 에디터에 설치된 JDK 경
geukggom.tistory.com
https://husk321.tistory.com/266
유니티 애드몹 적용 중 Gradle failed 대응해보기
유니티에 애드몹 한번 넣겠다고 오류 터지는걸 많이 봤는데 이번 Gradle failed 전에 한번 체크해야 될 사항들입니다. - 유니티에 안드로이드 빌드 설치되어 있는지 (안드로이드 sdk, openjdk 설치 포함
husk321.tistory.com
https://maeum123.tistory.com/145
유니티 애드몹 전면광고 안 나옴 - 해결 (Force Resolve)
오랜만에 어플을 출시했는데 광고가 계속 안 떴다. 테스트할 때도 잘 안 뜨긴 했지만, 테스트 광고는 원래 잘 안 떠서 일단 출시했다. 그런데 아무리 기다려도 광고가 안 나왔다. 작년에도 어플
maeum123.tistory.com
난 맨위에서 부터 아래까지를 겪었다고 보면 될거 같다
지금도 해결을 못한상태
리졸브가 성공했었고 유니티 내에서는 제대로 작동하지만 빌드시 작동되지 않았다 처음부터 다시했는데 리졸브가 분명 성공했었는데 찾아볼때 포스 리졸브를 해봐야 된다는 말이 있기에 하다가 실패해 그래들 페일 대응을 통해 시도해보고 있다
내 코드가 문제인지 모르겠는데 혹시 누군가 사용하고 코드에 문제가 있었다면 알려주길 바라며 올린다..
유니티 하단배너
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class AdmobBannerAd : MonoBehaviour
{
string adUnitId;
BannerView _bannerView;
public void Start()
{
MobileAds.Initialize((InitializationStatus initStatus) =>
{
//초기화 완료
});
#if UNITY_ANDROID
adUnitId = "ca-app-pub-3940256099942544/6300978111";//샘플코드
#elif UNITY_IOS
adUnitId = "ca-app-pub-3940256099942544/2934735716";
#else
adUnitId = "unexpected_platform";
#endif
LoadAd();
}
public void LoadAd()
{
// create an instance of a banner view first.
if (_bannerView == null)
{
CreateBannerView();
}
// create our request used to load the ad.
var adRequest = new AdRequest();
// send the request to load the ad.
Debug.Log("Loading banner ad.");
_bannerView.LoadAd(adRequest);
}
public void CreateBannerView() //광고 보여주기
{
Debug.Log("Creating banner view");
if (_bannerView != null)
{
DestroyAd();
}
AdSize adaptiveSize =
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);
_bannerView = new BannerView(adUnitId, adaptiveSize, AdPosition.Bottom);
//_bannerView = new BannerView(_adUnitId, AdSize.Banner, 0, 50);
}
private void ListenToAdEvents()
{
_bannerView.OnBannerAdLoaded += () =>
{
Debug.Log("Banner view loaded an ad with response : "
+ _bannerView.GetResponseInfo());
};
_bannerView.OnBannerAdLoadFailed += (LoadAdError error) =>
{
Debug.LogError("Banner view failed to load an ad with error : "
+ error);
};
_bannerView.OnAdPaid += (AdValue adValue) =>
{
Debug.Log(string.Format("Banner view paid {0} {1}.",
adValue.Value,
adValue.CurrencyCode));
};
_bannerView.OnAdImpressionRecorded += () =>
{
Debug.Log("Banner view recorded an impression.");
};
_bannerView.OnAdClicked += () =>
{
Debug.Log("Banner view was clicked.");
};
_bannerView.OnAdFullScreenContentOpened += (null);
{
Debug.Log("Banner view full screen content opened.");
};
_bannerView.OnAdFullScreenContentClosed += (null);
{
Debug.Log("Banner view full screen content closed.");
};
}
public void DestroyAd() //광고 제거
{
if (_bannerView != null)
{
Debug.Log("Destroying banner ad.");
_bannerView.Destroy();
_bannerView = null;
}
}
}
@@@@수정@@@@@
위에 블로그링크 젤 아래 경우가 나한테도 해당되는 경우 였다 자바 변수 설정을 해주고 포스 리졸브 다시 구웠더니
하단 배너 광고가 나왔다
빌드시 스코어 오류는 스코어 스크립트에 광고 스크립트를 섞어서 충돌나던것
분리해서 적용 시켜주자 잘적용이 되었다
솔직히 말해서 나는 아직 이 구글 애드몹 스크립트를 완전히 이해하지 못했다
그러나 나같은 사람들을 위해서 코드를 남긴다
아래의 코드에서 나는 업데이트 부분에서 플레이어가 죽었을때 광고가 나오게 되있다
응용해서 사용하길 바란다
ps. 더 나은 방법 ,설명 , 강의영상 ,유튜브 등이 있다면 추천바람
using GoogleMobileAds.Api;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PopUpAD : MonoBehaviour
{
string adUnitId;
private InterstitialAd interstitialAd;
bool check=false;
// Start is called before the first frame update
void Start()
{
MobileAds.Initialize((InitializationStatus initStatus) =>
{
//초기화 완료
});
#if UNITY_ANDROID
adUnitId = "ca-app-pub-3940256099942544/6300978111";
#elif UNITY_IOS
adUnitId = "ca-app-pub-3940256099942544/4411468910";
#else
adUnitId = "unexpected_platform";
#endif
LoadInterstitialAd();
}
// Update is called once per frame
void Update()
{
if (GameManager.Instance.IsDead)
{
if(!check)
ShowAd();
check = true;
}
}
public void LoadInterstitialAd() //광고 로드
{
if (interstitialAd != null)
{
interstitialAd.Destroy();
interstitialAd = null;
}
Debug.Log("Loading the interstitial ad.");
var adRequest = new AdRequest();
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 ShowAd() //광고 보기
{
if (interstitialAd != null && interstitialAd.CanShowAd())
{
Debug.Log("Showing interstitial ad.");
interstitialAd.Show();
}
else
{
LoadInterstitialAd(); //광고 재로드
Debug.LogError("Interstitial ad is not ready yet.");
}
}
private void RegisterEventHandlers(InterstitialAd ad) //광고 이벤트
{
ad.OnAdPaid += (AdValue adValue) =>
{
//보상 주기
Debug.Log(string.Format("Interstitial ad paid {0} {1}.",
adValue.Value,
adValue.CurrencyCode));
};
ad.OnAdImpressionRecorded += () =>
{
Debug.Log("Interstitial ad recorded an impression.");
};
ad.OnAdClicked += () =>
{
Debug.Log("Interstitial ad was clicked.");
};
ad.OnAdFullScreenContentOpened += () =>
{
Debug.Log("Interstitial ad full screen content opened.");
};
ad.OnAdFullScreenContentClosed += () =>
{
Debug.Log("Interstitial ad full screen content closed.");
};
ad.OnAdFullScreenContentFailed += (AdError error) =>
{
Debug.LogError("Interstitial ad failed to open full screen content " +
"with error : " + error);
};
}
}
'TIL' 카테고리의 다른 글
유니티 멀티 포톤 (0) | 2023.10.16 |
---|---|
유니티 깃 머지 주의사항 (0) | 2023.10.13 |
유니티 URP란 (0) | 2023.10.05 |
프로젝트 마무리 (0) | 2023.10.04 |
유니티 오브젝트 리스폰 시키기 (0) | 2023.09.27 |