Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 TERMINAL333 · Jan 30, 2015 at 12:11 PM · c#androidadmobadd

C# Script not running at all.

So i'm finishing up an android game, and i'm trying to add a small google add using admob in to it. I downloaded and imported all the things i had to. The demo scene works, but when i try to implement the script in to my game it doesn't. I usually write code in JS but for this purpose i had to do a little c# so i apologize if this is an obvious mistake. The code isn't even running. I added a debug.log in the start dunction but it's not showing up at all. Here's the code

EDIT 1: I forgot to mention I had to use a variable from another JS script. I put that script in Standard Assets so it compiles first and this should work.(It doens't give me any errors) But that's beside the point.

 using System;
 using UnityEngine;
 using GoogleMobileAds;
 using GoogleMobileAds.Api;
 // Example script showing how to invoke the Google Mobile Ads Unity plugin.
 public class AdManager : MonoBehaviour
 {
     bool shown = false;
     private GameManagerHard jsScript;
     private BannerView bannerView;
     private InterstitialAd interstitial;
 
     void Start()
     {
         RequestBanner();
         jsScript = this.GetComponent<GameManagerHard> ();
         Debug.Log ("start");
     }
     void Update()
     {
         if(jsScript.GO && !shown)
         {
             bannerView.Show();
             shown = true;
             Debug.Log (jsScript.GO);
         }
     }
 
     private void RequestBanner()
     {
         #if UNITY_EDITOR
         string adUnitId = "unused";
         #elif UNITY_ANDROID
         string adUnitId = "MY AD ID IS HERE";
         #elif UNITY_IPHONE
         string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
         #else
         string adUnitId = "unexpected_platform";
         #endif
         
         // Create a 320x50 banner at the top of the screen.
         bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Top);
         // Register for ad events.
         bannerView.AdLoaded += HandleAdLoaded;
         bannerView.AdFailedToLoad += HandleAdFailedToLoad;
         bannerView.AdOpened += HandleAdOpened;
         bannerView.AdClosing += HandleAdClosing;
         bannerView.AdClosed += HandleAdClosed;
         bannerView.AdLeftApplication += HandleAdLeftApplication;
         // Load a banner ad.
         bannerView.LoadAd(createAdRequest());
     }
     
     private void RequestInterstitial()
     {
         #if UNITY_EDITOR
         string adUnitId = "unused";
         #elif UNITY_ANDROID
         string adUnitId = "INSERT_ANDROID_INTERSTITIAL_AD_UNIT_ID_HERE";
         #elif UNITY_IPHONE
         string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
         #else
         string adUnitId = "unexpected_platform";
         #endif
         
         // Create an interstitial.
         interstitial = new InterstitialAd(adUnitId);
         // Register for ad events.
         interstitial.AdLoaded += HandleInterstitialLoaded;
         interstitial.AdFailedToLoad += HandleInterstitialFailedToLoad;
         interstitial.AdOpened += HandleInterstitialOpened;
         interstitial.AdClosing += HandleInterstitialClosing;
         interstitial.AdClosed += HandleInterstitialClosed;
         interstitial.AdLeftApplication += HandleInterstitialLeftApplication;
         // Load an interstitial ad.
         interstitial.LoadAd(createAdRequest());
     }
     
     // Returns an ad request with custom ad targeting.
     private AdRequest createAdRequest()
     {
         return new AdRequest.Builder()
             .AddTestDevice(AdRequest.TestDeviceSimulator)
                 .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
                 .AddKeyword("game")
                 .SetGender(Gender.Male)
                 .SetBirthday(new DateTime(1985, 1, 1))
                 .TagForChildDirectedTreatment(false)
                 .AddExtra("color_bg", "9B30FF")
                 .Build();
         
     }
     
     private void ShowInterstitial()
     {
         if (interstitial.IsLoaded())
         {
             interstitial.Show();
         }
         else
         {
             print("Interstitial is not ready yet.");
         }
     }
     
     #region Banner callback handlers
     
     public void HandleAdLoaded(object sender, EventArgs args)
     {
         print("HandleAdLoaded event received.");
     }
     
     public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
         print("HandleFailedToReceiveAd event received with message: " + args.Message);
     }
     
     public void HandleAdOpened(object sender, EventArgs args)
     {
         print("HandleAdOpened event received");
     }
     
     void HandleAdClosing(object sender, EventArgs args)
     {
         print("HandleAdClosing event received");
     }
     
     public void HandleAdClosed(object sender, EventArgs args)
     {
         print("HandleAdClosed event received");
     }
     
     public void HandleAdLeftApplication(object sender, EventArgs args)
     {
         print("HandleAdLeftApplication event received");
     }
     
     #endregion
     
     #region Interstitial callback handlers
     
     public void HandleInterstitialLoaded(object sender, EventArgs args)
     {
         print("HandleInterstitialLoaded event received.");
     }
     
     public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
     {
         print("HandleInterstitialFailedToLoad event received with message: " + args.Message);
     }
     
     public void HandleInterstitialOpened(object sender, EventArgs args)
     {
         print("HandleInterstitialOpened event received");
     }
     
     void HandleInterstitialClosing(object sender, EventArgs args)
     {
         print("HandleInterstitialClosing event received");
     }
     
     public void HandleInterstitialClosed(object sender, EventArgs args)
     {
         print("HandleInterstitialClosed event received");
     }
     
     public void HandleInterstitialLeftApplication(object sender, EventArgs args)
     {
         print("HandleInterstitialLeftApplication event received");
     }
     
     #endregion
 }



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 HarshadK · Jan 30, 2015 at 07:42 AM 2
Share

Is this script of yours attached to any gameobject in the scene?

avatar image Bonfire-Boy · Jan 30, 2015 at 01:18 PM 1
Share

or any active GameObject

avatar image TERMINAL333 · Jan 30, 2015 at 04:38 PM 0
Share

Yes. It's attached to the empty Game$$anonymous$$anager object that i use, as well as the javascript i'm trying to access.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

deactivate script for period of time after script is used. 0 Answers

new scene does not load when calling from HandleOnAdClosed callback of admob script 0 Answers

Admob works on an empty project but not on my actual project 0 Answers

Multiple Cars not working 1 Answer

new scene does not load when calling from HandleOnAdClosed callback of admob script 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