C# C错误表示“成员名称不能与其封闭类型相同”

C# C错误表示“成员名称不能与其封闭类型相同”,c#,C#,我得到一个错误,指出“damageScript”:成员名称不能与它们的封闭类型相同,它只显示了它所说的public-HealthDamageInfo-damageScript的位置 internal class damageScript { public HealthDamageInfo damageScript; public string tagName; public string otherTag; public string message;

我得到一个错误,指出“damageScript”:成员名称不能与它们的封闭类型相同,它只显示了它所说的public-HealthDamageInfo-damageScript的位置

internal class damageScript
{

    public HealthDamageInfo damageScript;




    public string tagName;
    public string otherTag;

    public string message;

    // Use this for initialization
    void Start()
    {
        damageScript = GetComponent<HealthDamageInfo>();
    }

    private HealthDamageInfo GetComponent<T>()
    {
        throw new NotImplementedException();
    }

    // Update is called once per frame
    void Update()
    {

    }

    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == tagName)
        {
            damageScript.SendMessage("SwitchInteractionTarget", message);
        }
        else if (other.gameObject.tag == otherTag)
        {
            damageScript.SendMessage("SwitchInteractionTarget", message);
        }
    }
}

正如错误所说,您的类damageScript也不能包含变量damageScript。如果重命名变量或类,错误将消失。

public Health DamageInfo damageScript;包含在内部类damageScript中


必须更改类名或成员变量。

所引用行的类名damageScript和字段damageScript具有相同的名称。将其中一个更改为其他名称。值得注意的是,您的类名没有遵循正确的C约定,即对类名进行PASCALCING。您应该将类重命名为内部类DamageScript