- Home /
EditorGUI Enum help
My gun script is this:
public enum GunType
{
singleShot,
rapidFire,
burst,
shotgun,
launcher
}
public GunType gunType;
My Editor script is this:
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(GunScript))]
public class GunEditorScript : Editor
{
public override void OnInspectorGUI()
{
GunScript myTarget = (GunScript)target;
myTarget.gunType = (GunType)EditorGUILayout.EnumPopup(myTarget.gunType);
}
}
Why cant I get this enumpopup to work?
Is the guntype enum defined INSIDE the GunScript class? If not, this looks ok to me; what happens?
It gives me an error saying: The Type or namespace name "GunType" could not be found. Are you missing a using directive or an assembly reference?
So, it sounds like you DID define the enum inside your GunScript. In that case you will need to refer to it's type as "GunScript.GunType"
myTarget.gunType = (GunScript.GunType)EditorGUILayout.EnumPopup(myTarget.gunType);
You $$anonymous$$AY even need to cast to that type type when passing IN the target's gunType.
myTarget.gunType = (GunScript.GunType)EditorGUILayout.EnumPopup((GunScript.GunType)myTarget.gunType);
Alternatively, you can define the enum OUTSIDE the class.
Answer by Bunny83 · Jun 28, 2016 at 11:35 PM
You're missing something that marks the object as dirty. SetDirty is deprecated for scene objects. You should use Undo.RecordObject.