C# 错误说" member names can not be the same as their enclosing type"



我收到一个错误,指出"'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 HealthDamageInfo damageScript;包含在internal class damageScript中。

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

相关内容

最新更新