不调用OnTriggerEnter()

编程入门 行业动态 更新时间:2024-10-23 17:37:30
本文介绍了不调用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()

本文发布于:2023-10-28 19:19:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537545.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:OnTriggerEnter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!