C# 必须是Collison2D类型,但我的代码不是关于Collison的

C# 必须是Collison2D类型,但我的代码不是关于Collison的,c#,unity3d,C#,Unity3d,这与碰撞无关,我该怎么办? 统一错误:此消息参数的类型必须为:Collison 2D IEnumerator bosstextgoaway() { yield return new WaitForSeconds(3f); BossText.text = ""; BossText.GetComponent<Text>().enabled = false; //this is the line with the error } IEnumer

这与碰撞无关,我该怎么办? 统一错误:此消息参数的类型必须为:Collison 2D

IEnumerator bosstextgoaway()
{
    yield return new WaitForSeconds(3f);
    BossText.text = "";
    BossText.GetComponent<Text>().enabled = false; //this is the line with the error
}
IEnumerator bosstextgoaway()
{
返回新的等待秒(3f);
BossText.text=“”;
BossText.GetComponent().enabled=false;//这是出现错误的行
}

您的BossText变量已经是对文本对象的引用。如果不是这样,您将无法获取文本对象的文本

但是一行之后,您尝试获取一个无法工作的文本对象的文本对象,您应该只调用文本对象上的.enabled

例如:

//对BossText对象的引用。
[序列化字段]专用文本BossText;
//停用文本框。
BossText.enabled=false;

BossText的定义在哪里?bossText是UI命名空间中的文本组件吗?如果是文本,为什么调用getcomponent如果已经是文本?请提供更多代码(BossText类),否则无法判断错误的来源。