我收到一个错误,指出"'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
中。
您必须更改类名或成员变量的。