如何通过来自3个不同游戏对象的触发器来显示游戏对象

时间:2016-12-21 13:32:26

标签: android unity3d unityscript augmented-reality vuforia

我正在使用Unity3D和Vuforia开发AR应用程序。

我完成了AR的所有基础知识,现在正在完成它。

但是,我目前陷入触发器部分。

我有3张抽认卡(1号,2号,加号)。我已经在每一个中放置了盒子对撞机,在1号和2号中放置了刚体.Plus卡作为触发器。

现在,我试图让每张卡片中的游戏对象在触发时消失,并在触发器发生时出现第四个游戏对象。第四个游戏对象是加法的结果(即1 + 2 = 3)。

我开发了以下代码。根据我给他们的标签触发游戏对象。游戏对象消失,但第四个游戏对象不会出现。我在这做错了什么?

#pragma strict

var mathplus : GameObject;
var sphere01 : GameObject;
var sphere02 : GameObject;
var result03 : GameObject;

function Start(){
    sphere01.SetActive(true);
    sphere02.SetActive(true);
    mathplus.SetActive(true);
    result03.SetActive(false);
}

function OnTriggerEnter (other : Collider) {
    Debug.Log("Object entered the trigger.");
    if (other.tag == "number01" && other.tag == "number02"){
        mathplus.SetActive(false);
        sphere01.SetActive(false);
        sphere02.SetActive(false);
        result03.SetActive(true);
    }
}

function OnTriggerExit (other : Collider) {
    Debug.Log("Object exited the trigger.");
    mathplus.SetActive(true);
    sphere01.SetActive(true);
    sphere02.SetActive(true);
    result03.SetActive(false);
}

数字卡中的游戏对象被称为" sphere",Plus卡中的游戏对象称为" mathplus",第四个游戏对象被称为" result03"

我希望有人可以帮助纠正这个问题。

谢谢和问候。

1 个答案:

答案 0 :(得分:1)

你犯了一个小错误。

这是因为第四张卡被禁用,所以它的对手也被禁用了。

你的逻辑是正确的,你应该做的是看不见卡4,而不是禁用它

禁用网格渲染以隐藏游戏对象

      GetComponent(MeshRenderer).enabled = false;

这是c#剧本,抱歉,我不太了解团结js。

您可以从invisible Gameobject and disable Gameobject

获取更多详细信息