这是针对 2D 游戏的。
我有一个可以射击触发射弹(带有触发对撞机)的玩家和可以做同样事情的敌人。当玩家射弹与敌人相撞时,事情就会发生,反之亦然。然而,当 Player 弹丸和 Enemy 弹丸碰撞时,它们只是忽略碰撞,互相穿过,什么都没有发生。他们还有一个带有连续碰撞检测的 Rigidbody2D。
有没有办法让它在这两个带有触发碰撞器的游戏对象接触时发生一些事情?
这是我为 Enemy 弹丸脚本准备的内容:
void OnTriggerEnter2D( Collider2D other ){
if (other.gameObject.name == "Ground"){
Destroy (gameObject);
}
else if (other.gameObject.name == "Player"){
other.gameObject.GetComponent<RControlScript>().RHealth = other.gameObject.GetComponent<RControlScript>().RHealth - damage;
Instantiate(transformInto, gameObject.transform.position, gameObject.transform.rotation);
Destroy (gameObject);
}
else if(other.gameObject.name == "Shot"){
Destroy (gameObject);
}
}
“Shot”是玩家射弹的名称,它是不与敌人射弹碰撞的游戏对象。