- Home /
EditorGUILayout.EnumPopup not found
I have this simple editor script and I can't seem to find the problem.
using UnityEngine;
using System.Collections;
public class Info : MonoBehaviour {
public enum Category {Armor, Consumable, Necklace, Ring, Scroll, Shield, Weapon}
public enum ArmorType {Breast, Feet, Hands, Head, Shoulder}
public string Name;
public Category category;
public ArmorType armorType;
public int Armor;
public int Health;
public int Mana;
public int Attack;
public int Intelligence;
}
Editor script is here; The 2 with the enumpopup do not work, it says missing category and armortype.
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Collections;
using System;
[CustomEditor(typeof(Info))]
public class InfoEditor : Editor
{
bool myBool = false;
public override void OnInspectorGUI()
{
myBool = EditorGUILayout.Toggle ("Show Original", myBool);
if (myBool == true) base.OnInspectorGUI();
Info myTarget = (Info)target;
myTarget.Name = EditorGUILayout.TextField("Name", myTarget.Name);
myTarget.category = (Category )EditorGUILayout.EnumPopup("Category", myTarget.category); // Error message here
myTarget.armorType = (ArmorType)EditorGUILayout.EnumPopup("Armor Type",myTarget.armorType); // Error message here
if (myTarget.category.ToString() == "Consumable"){
myTarget.Health = EditorGUILayout.IntField("Health", myTarget.Health);
myTarget.Mana = EditorGUILayout.IntField("Mana", myTarget.Mana);
}
if (myTarget.category.ToString() == "Armor"){
myTarget.Armor = EditorGUILayout.IntField("Armor", myTarget.Armor);
}
}
}
When I comment out those 2 errors everything else works. Could anyone find where the problem is?
Comment
Best Answer
Answer by Lo0NuhtiK · May 25, 2015 at 04:59 PM
You either need to move your two enums outside of the Info class... eg:
public enum Category{}
public enum ArmorType{}
public class Info{.....}
Or you need to do :
myTarget.category = (Info.Category )...
myTarget.armorType = (Info.ArmorType)...
Oh my goodness, didn't even notice I did that, I'm glad someone else looked at the code and caught it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613200251im_/https://answers.unity.com/themes/thub/images/avi.jpg)