【Unity】发生碰撞检测的必要条件

  • 翻译一下红色关键句:两个物体中任意一个必须有Rigidbody组件

 

OnTriggerEnter(Collider)

OnTriggerEnter is called when the GameObject collides with another GameObject.

The given other Collider has details about the trigger event, such as the name of its GameObject. Either of the two GameObjects must have a Rigidbodycomponent. The Rigidbody component has both Rigidbody.useGravity and Rigidbody.isKinematic set to false. These prevents the GameObject from falling under gravity and having kinematic behavior. One Collider has Collider.isTrigger set to true. The GameObject with Collider.isTrigger set to true has OnTriggerEnter called when the other GameObject touches or passes through it. OnTriggerEnter occurs after FixedUpdate ends.

A disabled GameObject receives the OnTriggerEnter message.

OnCollisionEnter(Collision)

OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

In contrast to OnTriggerEnterOnCollisionEnter is passed the Collision class and not a Collider. The Collision class contains information about contact points, impact velocity etc. If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Note: Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. Collision events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值