- Home /
admobdemo.cs is giving me an error
So I want to add a rewarded ad video inside my game, I watched a tutorial on how to do it and everything was fine than I wanted to test if the ad is working or not when suddenly this error messages pops up in the console Assets\admobdemo.cs(2,7): error CS0246: The type or namespace name "admob" could not be found (are you missing a using directive or an assembly reference?) & Assets\admobdemo.cs(4,2): error CS0246: The type or namespace name "Admob" could not be found (are you missing a using directive or an assembly reference?) This is the script : using UnityEngine; using admob; public class admobdemo : MonoBehaviour { Admob ad; //string appID=""; string bannerID = ""; string interstitialID = ""; string videoID = ""; string nativeBannerID = ""; void Awake() { Debug.Log("Awake is called!----------");
}
void Start()
{
Debug.Log("start unity demo-------------");
initAdmob();
}
void Update()
{
if (Input.GetKeyUp(KeyCode.Escape))
{
Debug.Log(KeyCode.Escape + "-----------------");
}
}
void initAdmob()
{
if UNITY_IOS
// appID="ca-app-pub-3940256099942544~1458002511";
bannerID="ca-app-pub-3940256099942544/2934735716";
interstitialID="ca-app-pub-3940256099942544/4411468910";
videoID="ca-app-pub-3940256099942544/1712485313";
nativeBannerID = "ca-app-pub-3940256099942544/3986624511";
elif UNITY_ANDROID
//appID="ca-app-pub-3940256099942544~3347511713";
bannerID = "ca-app-pub-3940256099942544/6300978111";
interstitialID = "ca-app-pub-3940256099942544/1033173712";
videoID = "ca-app-pub-3940256099942544/5224354917";
nativeBannerID = "ca-app-pub-3940256099942544/2247696110";
endif
AdProperties adProperties = new AdProperties();
/*
adProperties.isTesting(true);
adProperties.isAppMuted(true);
adProperties.isUnderAgeOfConsent(false);
adProperties.appVolume(100);
adProperties.maxAdContentRating(AdProperties.maxAdContentRating_G);
string[] keywords = { "key1", "key2", "key3" };
adProperties.keyworks(keywords);
*/
ad = Admob.Instance();
ad.bannerEventHandler += onBannerEvent;
ad.interstitialEventHandler += onInterstitialEvent;
ad.rewardedVideoEventHandler += onRewardedVideoEvent;
ad.nativeBannerEventHandler += onNativeBannerEvent;
ad.initSDK(adProperties);//reqired,adProperties can been null
}
void OnGUI()
{
if (GUI.Button(new Rect(120, 0, 100, 60), "showInterstitial"))
{
Debug.Log("touch inst button -------------");
if (ad.isInterstitialReady())
{
ad.showInterstitial();
}
else
{
ad.loadInterstitial(interstitialID);
}
}
if (GUI.Button(new Rect(0, 0, 100, 60), "showRewardVideo"))
{
Debug.Log("touch video button -------------");
if (ad.isRewardedVideoReady())
{
ad.showRewardedVideo();
}
else
{
ad.loadRewardedVideo(videoID);
}
}
if (GUI.Button(new Rect(0, 100, 100, 60), "showbanner"))
{
Admob.Instance().showBannerRelative(bannerID, AdSize.SMART_BANNER, AdPosition.BOTTOM_CENTER);
}
if (GUI.Button(new Rect(120, 100, 100, 60), "showbannerABS"))
{
Admob.Instance().showBannerAbsolute(bannerID, AdSize.BANNER, 20, 220, "mybanner");
}
if (GUI.Button(new Rect(240, 100, 100, 60), "removebanner"))
{
Admob.Instance().removeBanner();
Admob.Instance().removeBanner("mybanner");
}
if (GUI.Button(new Rect(0, 200, 100, 60), "showNative"))
{
Admob.Instance().showNativeBannerRelative(nativeBannerID, new AdSize(320, 280), AdPosition.BOTTOM_CENTER);
}
if (GUI.Button(new Rect(120, 200, 100, 60), "showNativeABS"))
{
Admob.Instance().showNativeBannerAbsolute(nativeBannerID, new AdSize(-1, 132), 0, 300);
}
if (GUI.Button(new Rect(240, 200, 100, 60), "removeNative"))
{
Admob.Instance().removeNativeBanner();
}
}
void onInterstitialEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobEvent---" + eventName + " " + msg);
if (eventName == AdmobEvent.onAdLoaded)
{
Admob.Instance().showInterstitial();
}
}
void onBannerEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobBannerEvent---" + eventName + " " + msg);
}
void onRewardedVideoEvent(string eventName, string msg)
{
Debug.Log("handler onRewardedVideoEvent---" + eventName + " rewarded: " + msg);
}
void onNativeBannerEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobNativeBannerEvent---" + eventName + " " + msg);
}
}
The script is not mine. I got it when I downloaded this zip file : https://github.com/googleads/googleads-mobile-unity/releases/tag/v4.0.0
Please I need help.
Answer by saadali211 · Oct 07, 2019 at 06:05 PM
admobdemo.cs will not work with admob sdk v4.0.0 download admob v3.18.3 the demo scripts does not comes with v4.0.0 i think they changed the Api's in version 4.0.0.
first they changed the code and included admobdemo.cs script now again in version 4.0.0 code is changed.
Thanks for the answer. Do you know where can I download admob v4.0.0?
Your answer
![](https://koobas.hobune.stream/wayback/20220612212917im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do you use an imported package in a script? 1 Answer
C# Script not running at all. 0 Answers