Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by unity_QV6GF9nylEY-Yg · Oct 02, 2021 at 03:10 AM · admobmonobehaviournew

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 => { });

     this.RequestBanner();
 }

 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();

     this.bannerView.LoadAd(request);
 }

}

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rohitvishwakarma1819 · Oct 02, 2021 at 05:25 AM 0
Share

Please explain your issue more clerly.

avatar image Bunny83 · Oct 02, 2021 at 07:22 AM 0
Share

I never used any advertisement. However it looks like non of the classes in the code you've showed is even a MonoBehaviour except for your enclosing "AdMob" component. So it's very unlikely that a potential error you get comes from this code snippet. Please, read the error carefully. You usually get an exact filename and a line number where the error happend.

Like it was already said, you haven't really added much useful information to your question. Did you actually attach your "AdMob" component to a gameobject in your scene? Do you somehow try to create an instance of your AdMob class manually, somewhere?

avatar image unity_QV6GF9nylEY-Yg · Oct 02, 2021 at 01:51 PM 0
Share

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 alt text

screenshot.jpg (297.9 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Oct 02, 2021 at 06:51 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unity_QV6GF9nylEY-Yg · Oct 02, 2021 at 07:11 PM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

128 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity - UI Dropdown uses constructor for DropDownItem 0 Answers

Unity 2D rotation speeds problem 1 Answer

You are trying to create a MonoBehaviour using the 'new' keyword. 2 Answers

"MonoBehaviour with new" warning has no line number 2 Answers

Why GetComponent()? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges