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. Dismiss Notice

Not working

Discussion in 'Scripting' started by qiqette, May 28, 2016.

  1. qiqette

    qiqette

    Joined:
    Feb 7, 2016
    Posts:
    121
    Code (CSharp):
    1.     public GameObject[] disabledItemsOnMenu;
    2. public void menuClick()
    3.     {
    4.  
    5.         Time.timeScale = 0;
    6.         foreach(GameObject disabledGO in disabledItemsOnMenu)
    7.         {
    8.             disabledGO.active = false;
    9.         }
    Ive got: Null reference exception: Object reference is not set to an instance of an object menu.menuclick()

    Code (CSharp):
    1.     public GameObject[] disabledItemsOnMenu; //every item that will be disabled visually when you open the menu
    2.  
    3.     void Start()
    4.     {
    5.         insideMenu.SetActive(false);
    6.     }
    7.    
    8.     public void menuClick()
    9.     {
    10.  
    11.         Time.timeScale = 0;
    12.         foreach(GameObject disabledGO in disabledItemsOnMenu)
    13.         {
    14.             disabledGO.SetActive(false);
    15.         }
    16.  
    Ive got: Null reference exception: Object reference is not set to an instance of an object menu.menuclick()
     
  2. Nitugard

    Nitugard

    Joined:
    May 10, 2015
    Posts:
    340
    Thread tittle should be meaningful.

    You didn't reference things correctly most likely.
     
    Polymorphik likes this.
  3. qiqette

    qiqette

    Joined:
    Feb 7, 2016
    Posts:
    121
    SOLVED
    Code (CSharp):
    1.     public GameObject[] disabledItemsOnMenu; //every item that will be disabled visually when you open the menu
    2.  
    3.    
    4.     public void menuClick()
    5.     {
    6.  
    7.         Time.timeScale = 0;
    8.         foreach(GameObject disabledGO in disabledItemsOnMenu)
    9.         {
    10.             if (disabledGO != null)
    11.             {
    12.             disabledGO.SetActive(false);
    13.             }
    14.         }
     
  4. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    I saw this title and I died a little inside.
     
    Nitugard and RavenOfCode like this.
  5. _FLX

    _FLX

    Joined:
    Nov 10, 2015
    Posts:
    85
    Can you now edit your title and set it to "Working" ? :)