
Unityを初めて2ヶ月になります。
AdMobの広告にチャレンジ中です。
エラーの対策を知りたいです!!
公式サイト?
https://developers.google.cn/admob/unity/banner?hl=ja
を見てやったのですが、
コードusing System; using UnityEngine; using GoogleMobileAds.Api; ... public class GoogleMobileAdsDemoScript : MonoBehaviour { private BannerView bannerView; ... public void Start() { // Initialize the Google Mobile Ads SDK. MobileAds.Initialize(initStatus => { }); this.RequestBanner(); } private void RequestBanner() { #if UNITY_ANDROID string adUnitId = "ca-app-pub-3940256099942544/6300978111"; #elif UNITY_IPHONE string adUnitId = "ca-app-pub-3940256099942544/2934735716"; #else string adUnitId = "unexpected_platform"; #endif // Create a 320x50 banner at the top of the screen. this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Top); // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the banner with the request. this.bannerView.LoadAd(request); } }
と書くと以下のようなエラーが出ます。
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor ()
ButtonBehaviour:.ctor ()
GoogleMobileAds.Unity.BannerClient:CreateButtonBehavior ()
色々調べたのですが、どうしたらいいのかわかりません。
助けてください。よろしくお願いします。
環境状況:
MacOS Monterey 12.0.1
unity Version:2020.03
Xcode Version 13.2.1 (13C100)
GoogleMobileAds-v6.1.2

