简体   繁体   English

Unity标签触发

[英]Unity Tag Triggering

void onCollisionEnter(Collision test)
{
        if (xTag.gameObject.tag == "Row 0, Col 0")
        {
            Debug.Log("X");
        }
}

And so my problem is I have two game objects (xTag and yTag) and when they touch the R0C0 game object (which happens to just be a box collider) I want it to print out as a test. 所以我的问题是我有两个游戏对象(xTag和yTag),当它们碰到R0C0游戏对象(恰好是盒子对撞机)时,我希望将其打印出来作为测试。 The two game objects xTag and yTag, and I have an array that I made and I add to an Array if xTag or yTag touches on R0C0 and so fourth. 这两个游戏对象xTag和yTag,我有一个数组,如果xTag或yTag触及R0C0,则添加到数组中,所以第四个。 My problem is that I am now testing and so that if the game object touches the other game object with the tag it prints this. 我的问题是,我现在正在测试,因此如果游戏对象使用标签触摸另一个游戏对象,它将进行打印。 Both xTag and YTag have tags along with the the colliders but nothing is working! xTag和YTag都具有对撞机标签,但没有任何作用!

You should be checking what test.collider.tag is. 您应该检查什么是test.collider.tag xTag's tag will always be the same. xTag的标签将始终相同。 you should check that test.collider.tag == xTag.tag assuming that onColliderEnter is on R0C0. 您应该假设onColliderEnter位于R0C0上, onColliderEnter检查test.collider.tag == xTag.tag xTag.tag。

Source: http://docs.unity3d.com/ScriptReference/Collision.html 来源: http//docs.unity3d.com/ScriptReference/Collision.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM