No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdMobManager.cs 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using GoogleMobileAds.Api;
  5. using System;
  6. public class AdMobManager : MonoBehaviour{
  7. [SerializeField] GameObject 廣告_pl;
  8. private BannerView bannerView;
  9. #if UNITY_ANDROID
  10. //private string _adUnitId = "ca-app-pub-3940256099942544/6300978111";
  11. private string _adUnitId = "ca-app-pub-3570555734266765/5732940619";
  12. #elif UNITY_IPHONE
  13. //private string _adUnitId = "ca-app-pub-3940256099942544/2934735716";
  14. private string _adUnitId = "ca-app-pub-3570555734266765/6059409528";
  15. #else
  16. private string _adUnitId = "unused";
  17. #endif
  18. // Start is called before the first frame update
  19. void Start(){
  20. MobileAds.Initialize(initStatus => { });
  21. }
  22. public void RequestBanner(){
  23. bannerView?.Destroy();
  24. this.bannerView = new BannerView(_adUnitId,AdSize.Leaderboard, AdPosition.BottomLeft);
  25. AdRequest request = new();
  26. this.bannerView.LoadAd(request);
  27. }
  28. public void HideBanner(){
  29. bannerView?.Destroy();
  30. }
  31. }