- Home /
I can't use google admob ads
I can load and show the ads on the computer, but when I open it on the android platform, it either freezes while loading and the application closes or does not show. I get one error and that's it ;
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.RewardingAdBaseClient:CreateButtonBehavior() (at F:/Projeler/Intergalactic 2 - 2/Assets/GoogleMobileAds/Platforms/Unity/RewardingAdBaseClient.cs:90) GoogleMobileAds.Unity.RewardingAdBaseClient:Show() (at F:/Projeler/Intergalactic 2 - 2/Assets/GoogleMobileAds/Platforms/Unity/RewardingAdBaseClient.cs:154) GoogleMobileAds.Api.RewardedAd:Show() (at F:/Projeler/Intergalactic 2 - 2/Assets/GoogleMobileAds/Api/RewardedAd.cs:120) Reklamlar:ÖdüllüReklamGöster() (at F:/Projeler/Intergalactic 2 - 2/Assets/Scripts/Reklamlar.cs:29) Panel:respawn() (at F:/Projeler/Intergalactic 2 - 2/Assets/Scripts/Panel.cs:323) UnityEngine.EventSystems.EventSystem:Update()
Answer by NouamaneRaji · Mar 06, 2021 at 06:27 PM
the error come from : BannerClient class
private void CreateButtonBehavior()
{
buttonBehaviour = new ButtonBehaviour(); // this line exactly
buttonBehaviour.OnAdOpening += OnAdOpening;
buttonBehaviour.OnLeavingApplication += OnAdLeavingApplication;
}
' while
public class ButtonBehaviour : MonoBehaviour
{
public event EventHandler<EventArgs> OnAdOpening;
public event EventHandler<EventArgs> OnLeavingApplication;
public void OpenURL()
{
Debug.Log("Opened URL");
Application.OpenURL("http://google.com");
if (OnAdOpening != null)
{
OnAdOpening.Invoke(this, new EventArgs());
}
if (OnLeavingApplication != null)
{
OnLeavingApplication.Invoke(this, new EventArgs());
}
}
}
if you change inheritance from MonoBehaviour to ScriptableObject it will fix it. But I don't know if we have the rights to modify the library
Your answer
Follow this Question
Related Questions
My game crashing when I load or show an rewarded ads. 1 Answer
Stop Editor From Crashing 1 Answer
Error when building Game 0 Answers
How do I report a bug in Unity? 2 Answers