首页 > 解决方案 > 标记为覆盖但找不到合适的方法覆盖的 Unity 错误

问题描述

我正在编写一个统一的字符控制器。我是 C# 编程的新手,我写了一些代码,

using UnityEngine;
using UnityEditor;

[CustomPorpertyDrawer(typeof(AxisKeys))]
public class PlayerAxisKeysDrawer: PropertyDrawer{

    public override void onGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //don't indent
        int indent = EditorGUI.indentLevel;
        EditorGUI.indentLevel = 0;

        //ensure override works on entire property
        EditorGUI.BeginProperty(position, label, property);

        //label
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        //set position rects;
        Rect posLabel = new Rect(position.x, position.y, 15, position.height);
        Rect posField = new Rect(position.x + 20, position.y, 50, position.height);

        Rect negLabel = new Rect(position.x, position.y, 15, position.height);
        Rect negField = new Rect(position.x + 20, position.y, 50, position.height);

        GUIContent posGUI = new GUIContent("+");
        GUIContent negGUI = new GUIContent("-");

        //draw fields
        EditorGUI.LabelField(posLabel, posGUI);
        EditorGUI.PropertyField(posField, property.FindPropertyRelative("positive"), GUIContent.none);
        EditorGUI.LabelField(negLabel, negGUI);
        EditorGUI.PropertyField(negField, property.FindPropertyRelative("negative"), GUIContent.none);

        //reset indent
        EditorGUI.indentlevel = indent;

        //end property
        EditorGUI.EndProperty();
    }
}

但是得到这个错误。有人可以帮忙吗?

 error CS0115: `PlayerAxisKeysDrawer.onGUI(UnityEngine.Rect, UnityEditor.SerializedProperty, UnityEngine.GUIContent)' is marked as an override but no suitable method found to override

标签: c#unity3d

解决方案


您有拼写错误,更改OnInspectecorGUIOnInspectorGUI它应该可以工作:)


推荐阅读