Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么unity使用OnTiggerEnter()关闭我的画布?在Untiy2d中使用碰撞器的Acitvate文本_C#_Unity3d_Canvas_Text_Topdown - Fatal编程技术网

C# 为什么unity使用OnTiggerEnter()关闭我的画布?在Untiy2d中使用碰撞器的Acitvate文本

C# 为什么unity使用OnTiggerEnter()关闭我的画布?在Untiy2d中使用碰撞器的Acitvate文本,c#,unity3d,canvas,text,topdown,C#,Unity3d,Canvas,Text,Topdown,我无法使用可交互(Coin)脚本和OnTiggerEnter()激活画布。当我的播放器与我的硬币碰撞时,我想激活画布(显示我的文本)。脚本在我的硬币游戏对象中。我的硬币对撞机在IsTrigger上 public string displayText; public Text textView; public GameObject Player; public Canvas textCanvas; // Start is called before the first frame update

我无法使用可交互(Coin)脚本和OnTiggerEnter()激活画布。当我的播放器与我的硬币碰撞时,我想激活画布(显示我的文本)。脚本在我的硬币游戏对象中。我的硬币对撞机在IsTrigger上

public string displayText;
public Text textView;
public GameObject Player;
public Canvas textCanvas;

// Start is called before the first frame update
void Start()
{
    textCanvas.enabled = false;
}

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

}

void onTriggerEnter(Collider2D other)
{
    if (other.gameObject.tag == "Player")
    {
        textCanvas.enabled = true;
        textView.text = displayText;

    }
}

我尝试在没有画布的情况下只显示文本并观看教程。

问题在于,对于2D碰撞,方法名称是“OnTiggerEnter2D”,而不是“OnTiggerEnter”。这个sho

你的碰撞游戏对象是否连接了碰撞器?既然你使用了Collider2D,你是在2D空间吗?是的,这是一个2D自上而下的游戏,两个游戏对象都有一个碰撞器。我现在无法测试它,但你也应该使用
other.compareTag(“玩家”)因为它具有较少的CIL指令。还要检查标记是否正确写入,并尝试
Debug.Log(other.tag)
这样你就可以看到你的硬币是否发生了碰撞,以及与之发生了什么碰撞。compareTag()不是问题,它永远不会出现在OnTiggerEnter()函数中,这就是问题所在,Debug.Log(other.tag);永远不会显示,谢谢你的帮助。是的,非常感谢,我太笨了,我现在应该休息一下了。不用担心,Unity的单行为函数非常糟糕,我与它XS斗争了很多