Hi everyone. My custom class is
[System.Serializable]
public class Property
{
public enum properties
{
AddCalories,
AddWater,
AddVitaminA,
AddVitaminB1,
AddVitaminB2,
AddVitaminB3,
AddVitaminB5,
AddVitaminB6,
AddVitaminB12,
AddVitaminC,
AddVitaminD,
AddVitaminE,
AddVitaminK,
AddCalcium,
AddChromium,
AddIron,
AddZinc,
AddRadiation
}
public properties property;
public float value;
}
Then I have a game object with a script which has an array of this class “Property”.
The script is very simple:
public class HeartBeat_FoodItem : MonoBehaviour {
public Property[] properties;
}
The thing I want to do is detect whenever a certain property in the enum is selected (in the inspector), so a label could appear in that specific area (below the value float field).

The script for the editor is this:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(HeartBeat_FoodItem))]
public class HeartBeat_FoodItemEditor : Editor
{
public override void OnInspectorGUI()
{
serializedObject.Update();
SerializedProperty list = serializedObject.FindProperty("properties");
EditorGUILayout.PropertyField(list, true); //true means includeChildren=true, which allows me to expand and collapse the array.
EditorGUILayout.HelpBox("The value is measured in µg (micrograms).", MessageType.Info);
serializedObject.ApplyModifiedProperties();
}
}
I hope I provided enough information. Thanks in advance.
From Glurth: To elaborate, if you wish to use the serialized property route, you can do: serializedObject.Update(); SerializedProperty myEnum = serializedObject.FindProperty("enumName"); EditorGUILayout.PropertyField(myEnum); if (myEnum.intValue == (int)EnumType.ElementOne) { // do something } if (myEnum.intValue == (int)EnumType.ElementTwo) { // do something else etc... } serializedObject.ApplyModifiedProperties();
– NeedsLoomisAdd a bool variable that is false by default, when the first click occurs you set it to true, lets call that variable isGameStarted. Set it to false when the time runs out
– Landern