MonoBehaviours can only be added using AddComponent(). Alternatively.

Could I get some help to fix these 2 lines of my code? I know what the problem is but honestly don’t know how to fix it, Ive seen many examples but I don’t know how to apply it to MY code

using System;
using UnityEngine;
using GoogleMobileAds.Api;

public class AdMob : MonoBehaviour
private BannerView bannerView;

public void Start()
    MobileAds.Initialize(initStatus => { });


private void RequestBanner()
    string adUnitId = "ca-app-pub-7396991836824042/1028963955";

    this.bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom);

    AdRequest request = new AdRequest.Builder().Build();



Thank you, I actually did fix a bit of the problem by taking another look at the console, now the built goes through, no ad though and get same console message… So i have a little game and i wanted to ad a banner to it using Google Admob. I got the banner to work in unity but i keep getting this warning and of course, the banner does not come up in the apk. The script is attached to a Game Object, I actually followed the Admob guide and a few tutorials, there are actually forums about that same problem, seems to be an easy fix, get rid of “new” somehow using AddComponent() (or so I’ve read), but I am so new at coding that I don’t know how to do it on my code. Maybe this image explains it better

It’s an old issue in the Android Admob plugin. This has already been asked in january this year. There also is already an issue submitted to the google github repository about that issue.

As you can see in the issue, there was already an SO question about the same issue.

So the issue is that the library you’re using is faulty. It could have never worked in the first place. I don’t know if those who have created this library never actually tried it in Unity. As you can read in the other Unity answers question, you may be able to simply remove the “MonoBehaviour” base class from the “ButtonBehaviour” class. However I would also not recommend messing around with the library, especially when you don’t understand the innerworkings.

So there’s little you can do here. Either you increase the pressure on the github issue page so they may start fixing it some time in the future, or you try to fix it yourself. We won’t fix a google library here in UA, sorry.

Yes I saw that issue trend but as i said, i didnt know how to do it on my script. Anyway, I’ll figure it out, thank you.