Unity 如何在另一个对象发生碰撞时关闭游戏对象的网格碰撞器?
Unity How to turn off a gameObject's Mesh Collider when a collison on another object is done?
在我的 unity 项目中,我遇到了一个问题,我想与一个对象发生碰撞,然后我想打开另一个游戏对象的网格碰撞器,这是我现在的代码...
#pragma strict
private var objManager : ObjectiveManager;
private var ob2 : MeshCollider;
function Start()
{
objManager = GameObject.Find("3rdPersonController").GetComponent(ObjectiveManager);
ob2 = GameObject.Find("Objective2").GetComponent(MeshCollider);
}
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == "3rdPersonController")
ob2.enabled = true;
Debug.Log("whooop");
Destroy(gameObject);
objManager.objective1 = true;
objManager.objective2 = false;
objManager.objective3 = false;
objManager.objective4 = false;
objManager.objective5 = false;
objManager.objective6 = false;
objManager.objective7 = false;
objManager.objective8 = false;
objManager.objective9 = false;
objManager.objective10 = false;
objManager.objective11 = false;
objManager.objective12 = false;
}
只需将此作为答案发布即可关闭。
这里的问题是你的 If-statement 没有大括号,导致它后面的代码 运行 无论布尔值如何计算。
在我的 unity 项目中,我遇到了一个问题,我想与一个对象发生碰撞,然后我想打开另一个游戏对象的网格碰撞器,这是我现在的代码...
#pragma strict
private var objManager : ObjectiveManager;
private var ob2 : MeshCollider;
function Start()
{
objManager = GameObject.Find("3rdPersonController").GetComponent(ObjectiveManager);
ob2 = GameObject.Find("Objective2").GetComponent(MeshCollider);
}
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == "3rdPersonController")
ob2.enabled = true;
Debug.Log("whooop");
Destroy(gameObject);
objManager.objective1 = true;
objManager.objective2 = false;
objManager.objective3 = false;
objManager.objective4 = false;
objManager.objective5 = false;
objManager.objective6 = false;
objManager.objective7 = false;
objManager.objective8 = false;
objManager.objective9 = false;
objManager.objective10 = false;
objManager.objective11 = false;
objManager.objective12 = false;
}
只需将此作为答案发布即可关闭。
这里的问题是你的 If-statement 没有大括号,导致它后面的代码 运行 无论布尔值如何计算。