change the name of List elements in the inspector

I tried to do it here

but not work, i make a script :
NamedArrayAttribute:

using UnityEngine;
 
public class NamedArrayAttribute : PropertyAttribute
{
    public readonly string[] names;
    public NamedArrayAttribute(string[] names) { this.names = names; }
}

PropertyDrawer:

using UnityEngine;
using UnityEditor;
 
[CustomPropertyDrawer (typeof(NamedArrayAttribute))]public class NamedArrayDrawer : PropertyDrawer
{
    public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
    {
        try {
            int pos = int.Parse(property.propertyPath.Split('[', ']')[1]);
            EditorGUI.ObjectField(rect, property, new GUIContent(((NamedArrayAttribute)attribute).names[pos]));
        } catch {
            EditorGUI.ObjectField(rect, property, label);
        }
    }
}

but namespace name “NamedArrayAttribute” could not be found

Make sure you declared your “NamedArrayAttribute” inside a runtime class, not inside an editor file. The attribute need to be part of the runtime. If you declare it inside an editor script it is not available for your runtime scripts. So you can not declare the attribute definition inside the same file as your propertydrawer.

It’s best practise to place the attribute definition in a seperate file that has the filename matching with the defined type. So create a “NamedArrayAttribute.cs” file somewhere inside your assets folder but not inside an editor folder.