- Home /
Changing enum values with int label
Hello guys,
as i said in the title i want to change enum values.Script works fine, when i am setting new value it goes back to zero never sets a new value sorry for bad english and thanks.
Code:
string[] names = Enum.GetNames(typeof(Enemy.CombatSkills));
int[] vals = (int[])Enum.GetValues(typeof(Enemy.CombatSkills));
for(int y = 0; y < Enum.GetValues(typeof(Enemy.CombatSkills)).Length;y++)
{
EditorGUILayout.BeginHorizontal();
EditorGUI.indentLevel += 1;
vals[y] = EditorGUILayout.IntField(names[y],vals[y]);
EditorGUI.indentLevel -= 1;
EditorGUILayout.EndHorizontal();
}
Comment
Why dont you use Enum popup in this case?
http://docs.unity3d.com/Documentation/ScriptReference/EditorGUILayout.EnumPopup.html
Answer by kral · Sep 21, 2013 at 12:35 AM
nevermind i figured out.Just moved this two lines to enemy class.
string[] names = Enum.GetNames(typeof(Enemy.CombatSkills));
int[] vals = (int[])Enum.GetValues(typeof(Enemy.CombatSkills));
and
for(int y = 0; y < Enum.GetValues(typeof(Enemy.CombatSkills)).Length;y++)
{
EditorGUILayout.BeginHorizontal();
EditorGUI.indentLevel += 1;
enemy[i].vals[y] = EditorGUILayout.IntField(enemy[i].names[y],enemy[i].vals[y]);
EditorGUI.indentLevel -= 1;
EditorGUILayout.EndHorizontal();
}