If I create a boolean array:
public bool[] boolArray;
Then the inspector shows me boolean tick-boxes named “Element 0, Element 1” etc. which isn’t really helpful… how can I change it so that each element in the array has an actual name?
If I create a boolean array:
public bool[] boolArray;
Then the inspector shows me boolean tick-boxes named “Element 0, Element 1” etc. which isn’t really helpful… how can I change it so that each element in the array has an actual name?
It sounds like you might need a Dictionary instead. A Dictionary is a datastructure that allows you to link a key to the values that go into the structure. A typical use case is a phonebook, where you link the name of a person (the key is then a string) to his/her phone-number (the value is then an integer).
Try something like this:
Dictionary<string, Boolean> NamedBooleans = new Dictionary<string, bool>();
NamedBooleans.Add("This is the name of the first boolean", false);
NamedBooleans.Add("This is the name of the second boolean", true);
Then, later on, you can look up the booleans like this, for example:
if (NamedBooleans["This is the name of the first boolean"])
{
// Yada yada
}
As far as I am aware you can’t assign a name to a boolean, there may be a way of serializing the boolean with a
name but I’m not sure.
#1) use a Hashtable to store the booleans:
var hashtable = {};
function Start(){
hashtable["My boolean"] = true;
hashtable["Another boolean"] = false;
}
then you can refer to them now like so…
if(hashtable["My boolean"]){
//do stuff
}
#2) make class object for a named boolean:
var array : NamedBoolean[];
class NamedBoolean {
var name : string;
var bool : boolean;
}
with a class object they will show in the inspector as the “name” variable you assign.
refer to them like so:
if(array*.bool){*
//do stuff
}
#3) similar to a hashtable you could use a generic list
var myList = new List.();
then you can refer to them now like so…
if(myList[“My boolean”]){
//do stuff
}