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

creating a list of bools in OnInspectorGUI()

Discussion in 'Scripting' started by FisherM, Dec 7, 2014.

  1. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    the bool never applys and I cannot tick the box
    Code (CSharp):
    1.  
    2.             int index = 0;
    3.             foreach(var Attack in AD.Attacks.Values)
    4.             {
    5.                 GUILayout.Label(Attack.AttackName);
    6.                 index++;
    7.             }
    8.             bool[] Attacks = new bool[index];
    9.             for(int i = 0 ; i < index ; i++)
    10.             {
    11.                 Attacks[i] = GUILayout.Toggle (Attacks[i], "");
    12.             }
     
    Last edited: Dec 7, 2014
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You are recreating the boolean array every time OnInspectorGUI is called.
     
  3. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    If I put the
    "bool[] Attacks;"
    outside of the function it doesn't have a length so I get called to an object that doesn't exist
     
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Then initialise it somewhere, maybe in Reset() or OnEnable(). How permanent do you want this array? Do you want it serialised?