我正在尝试检测子弹(具有刚体和盒子对撞机)是否击中了我的模型(具有 CharacterController 和网格对撞机),但它不起作用。如果我在一个立方体(也有一个 CharacterController 和一个 Box Collider)上尝试相同的脚本,它工作得非常好。我曾尝试将其设为触发器并使用 OnTriggerEnter,但它仍然无法在模型上运行,但在多维数据集上也能正常运行。这是我的代码。
function OnControllerColliderHit (hit : ControllerColliderHit)
{
//doesnt work for either of them
if(hit.gameObject.tag == "bullet")
{
print("i have been hit by a bullet");
}
}
function OnTriggerEnter(hit : Collider)
{
//works for the cube and not the model
if(hit.gameObject.tag == "bullet")
{
print("i have been hit by trigger hit ");
}
}
function OnCollisionEnter(hit: Collision)
{
//works for the cube and not the model
if(hit.gameObject.tag == "bullet")
{
print("i have been hit by trigger hit ")
}
}