未检测到Unity冲突 [英] Unity collision not being detected
问题描述
我正在学习统一创建一个简单的fps游戏的问题,例如当我的玩家在地面控制台上最初通过"Debug.log(collision.gameObject)"打印"floor"时,碰撞不会自行更新但是当它与其他对象相交时,例如多维数据集控制台将打印出多维数据集",但是当我离开它时,控制台不会变回地板",为什么???
I am learning to create a simple fps game in unity the problem is that the collision does not update itself for example initially when my player is on the ground console prints "floor" by "Debug.log(collision.gameObject)" but when it intersects other objects such as a cube console will print out "cube" but when I walk away from it , console does not change back to "floor" Why????
我正在使用transform.translate进行移动和跳跃,并使用OnCollisionEnter方法进行碰撞检测
I am using transform.translate to move and jump and using method OnCollisionEnter for collision detection
推荐答案
OnCollisionEnter
仅在对象进入对撞机时触发.
OnCollisionEnter
is triggered only when object enters the collider.
A)列出所有遇到的对象,方法是在发生OnCollisionEnter
时将其添加,并在发生OnCollisionExit
时将其删除.然后,每当需要确保自己在地板"上时,请在列表中进行检查.
A) Make a list of all encountered objects by adding them when OnCollisionEnter
happens and removing when OnCollisionExit
happens. Then whenever you need to make sure you are on "floor" check it in the list.
B)使用OnCollisionStay
,如果您触摸地板",则会收到每一帧的通知.
B) Use OnCollisionStay
and every frame you will be notified if you are touching the "floor".
这篇关于未检测到Unity冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!