Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why is Debug.Log not showing in my console for this script?

Discussion in 'Scripting' started by Venatal, Jan 4, 2016.

  1. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    ** Why is Debug.Log not shown in my console is what I meant to write :/**
    Code (CSharp):
    1.  
    2. void Start()
    3.     {
    4.         if (Done == true)
    5.         {
    6.             bannerView.Show();
    7.             Done = false;
    8.             return;
    9.         }
    10.  
    11.         if (SceneManager.GetActiveScene().buildIndex == 1)
    12.         {
    13.             bannerView.Hide();
    14.             Debug.Log("Banner hidden");
    15.             return;
    16.         }
    17.     }
    18.  
    When I enter my next scene it should show in my console "Banner hidden" but It doesn't show it, any ideas?
    I want it to execute the following code when I press play and the next scene loads.
    thanks in advance.
     
    Last edited: Jan 4, 2016
  2. apsdsm

    apsdsm

    Joined:
    Sep 26, 2013
    Posts:
    56
    Fist try debugging to see if you're hitting that debug statement inside that that block. Next check to see if you have anything disabled in the editor (like output turned off). That might be a good place to start...
     
  3. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    I'm not sure exactly what you mean by turning output off but I have other scripts which contain Debug.Log and they register it only seems to be this one that won't :/
    It's as if
    Code (CSharp):
    1.  if (SceneManager.GetActiveScene().buildIndex == 1)
    isn't working at all.
     
    Last edited: Jan 4, 2016
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    If you put a break point in & hover the mouse over the bits of that line you can see what value is being passed for the buildindex. If the debug.log isn't working then the buildindex value mustn't be == 1. Is this happening on the first scene? If so that could be the issue as the first scene is 0
     
  5. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    It worked before the update when I used
    Code (CSharp):
    1. Application.loadedlevelname == "level"
    and isn't that the same as
    Code (CSharp):
    1. SceneManager.GetActiveScene().name == "Level"
    in 5.3.1 which dosen't seem to work either....
     
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you can change a thread's title any time you want, top right "thread tools"... :)


    @Venatal you've got a "level" (lowercase) and "Level" (uppercase) there, not sure if that's just a typo bringing it into the forums?
     
  7. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    If you add a few more debug statements and then run the program, depending on what you see in the console it should give you a better idea of what's going on.

    Code (CSharp):
    1.  
    2. void Start()
    3.     {
    4.         Debug.Log("Start");
    5.         if (Done == true)
    6.         {
    7.             Debug.Log("Done = true");
    8.             bannerView.Show();
    9.             Done = false;
    10.             return;
    11.         }
    12.  
    13.         Debug.Log("build index " + SceneManager.GetActiveScene().buildIndex);
    14.         if (SceneManager.GetActiveScene().buildIndex == 1)
    15.         {
    16.             bannerView.Hide();
    17.             Debug.Log("Banner hidden");
    18.             return;
    19.         }
    20.         Debug.Log("End of Start");
    21.     }
    22.  
     
  8. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    It only showed "Start" and "Done = true" in the console and nothing else. I have no clue as to why its doing that :/
    This is the whole script which I slightly changed, still doesn't work either :(
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using GoogleMobileAds.Api;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class Bannerad : MonoBehaviour
    7. {
    8.     public static Bannerad manager;
    9.     private BannerView bannerView;
    10.  
    11.     void Awake()
    12.     {
    13.         RequestBanner();
    14.         manager = this;
    15.     }
    16.  
    17.     void Start()
    18.     {
    19.         bannerView.Show();
    20.      
    21.         if (SceneManager.GetActiveScene().name == "Level")
    22.         {
    23.             bannerView.Hide();
    24.             bannerView.Destroy();
    25.             Debug.Log("Banner Hidden, Destroyed and a new one is requested.");
    26.             RequestBanner();
    27.             return;
    28.         }
    29.     }
    30.  
    31.     void RequestBanner()
    32.     {
    33. #if UNITY_ANDROID
    34.         string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    35. #elif UNITY_IPHONE
    36.         string adUnitId = "INSERT_IOS_BANNER_AD_UNIT_ID_HERE";
    37. #else
    38.         string adUnitId = "unexpected_platform";
    39. #endif
    40.  
    41.         // Create a 320x50 banner at the top of the screen.
    42.         bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom);
    43.         // Create an empty ad request.
    44.         AdRequest request = new AdRequest.Builder().Build();
    45.         // Load the banner with the request.
    46.         bannerView.LoadAd(request);
    47.     }
    48.  
    49.     public void ShowBanner()
    50.     {
    51.         bannerView.Show();
    52.     }
    53. }
    54.  
    55.  
     
    Last edited: Jan 4, 2016
  9. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    That was just a typo it should be "Level"
     
  10. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    In your earlier code 'done' is obviously true when the start function is called, as the debug.log result shows. And as start is only ever called once on the script, the rest of the code in the start function will never be run, so there's a logic flow error there somewhere.

    Regarding the new code you posted, I'm not entirely familiar with the ads system you are using (is it admob?), but with ad systems that I've used there has always been some kind of isAdReady function which you need to check is true before you try to display the ad, and I can't see anything like that in your code.

    So it may be that you are trying to display an ad when one isn't ready. Other than that I can't really offer any more help.
     
  11. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    But even if I use FixedUpdate for the scenemanger component it still doesn't show up in the console.
    The code worked perfectly before I updated to 5.3.1 from 5.2.2. There must be something I'm missing but can't for the life of me figure out what it is atm.
     
  12. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    I am seeing similar things with static methods. This debug never shows up in console. This class has static variables and static methods in it. I even tried the make the class static which created more coding problems. I even set the execution order in preferences.
    Code (CSharp):
    1.  void Awake()
    2.     {
    3.         Debug.Log("AccountManager.Awake()");
    4.     }