Hi everyone, I have been trying to get mylist equal to the number of strings in Text but I keep getting an invalid arguments error. my goal is to get the number of GUILayout.buttons to equal Text.Count.
public class ButtonExample:monobehaviour(){
[System.Serializable]
public class IntValueClass
{
public int IntValue = 0;
}
public List<IntValueClass> MyList = new List<IntValueClass>();
public string[] Text;
void OnGUI(){
Text = new string(){"text1","text2","text3",text4"};
MyList = new List<IntValueClass>(Text);//error has invalid arguments
for (int i = 0; i < Text.Length; i++)
GUILayout.Label(Text*, GUILayout.Width(125), GUILayout.Height(25));*
for (int e = 0; e <MyList.Count; e++){
if (GUILayout.Button(“+”, GUILayout.Width(25), GUILayout.Height(25)))
{
*SpellList[e].IntValue++; *
}
}
}
I believe the problem is your list is of type “IntValueClass”, but you are trying to copy an array of strings, rather than IntValueClass’s… But if I understand correctly, you meant to set the SIZE of the list, so you want an int for the argument:
MyList = new List<IntValueClass>(Text.Length);
I think that’s what you meant.
[System.Serializable]
public class ButtonExample : MonoBehaviour
{
public string Text = new string[4] {“text1”, “text2”, “text3”, “text4”};
public List MyList = new List();
public class IntValueClass
{
public int IntValue;
public IntValueClass(int start_value)
{
IntValue = start_value;
}
}
void Start()
{
foreach(string s in Text)
MyList.Add(new IntValueClass(1));
}
void OnGUI()
{
for(int i = 0; i < Text.Length; i++)
{
GUILayout.Label(Text*, GUILayout.Width(125), GUILayout.Height(25));*
_ MyList*.IntValue++;_
_ }_
_ }_
_ }_
_}*_
might help
BurgZergArcage on how to make statistics.