本文介绍了不调用OnTriggerEnter()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个玩家(球体)和4个敌人(胶囊).所有敌人都添加了角色控制器.它们还都有一个子游戏对象,该对象具有RigidBody(无质量,无重力)和附加的Box Collider.Box Collider足够大,因此您可以看到盒子内部的球体模型,即使它们之间只有很小的空间.

I have a player (sphere) and 4 enemies (capsules). All enemies have a character controller added. They also all have a child GameObject, which has a RigidBody (no mass, no gravity) and a Box Collider attached. The Box Collider is large enough so you can see the sphere model inside of the box, even with a little space in between.

玩家还具有角色控制器,但没有RigidBody.它的球体确实与网格对撞机相连.

The player also has a character controller, but no RigidBody. It does have a sphere attached with a mesh collider.

所有敌人都选中了触发"框.他们为什么不调用OnTriggerEnter()函数?请注意,当敌人碰撞时,将调用OnTriggerEnter().但这对播放器不起作用.

All of the enemies have the IsTrigger box checked. Why don't they call the OnTriggerEnter() function? Note that when enemies collide, OnTriggerEnter() is called. But it doesn't work on the player.

推荐答案

球体是游戏者的子GameObject,还是GameObject本身?您可能要检查脚本的附加位置.如果脚本已附加到播放器上,但对撞机位于子GameObject上,那将无法正常工作.对撞机和脚本必须在同一个GameObject上.

Is the sphere a child GameObject to the player, or is it the GameObject itself? You might want to check where the script is attached. If the script is attached to the player but the collider is on a child GameObject, that isn't quite going to work. Collider and script need to be on the same GameObject.

这篇关于不调用OnTriggerEnter()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 10:49