- 翻译一下红色关键句:两个物体中任意一个必须有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 OnTriggerEnter, OnCollisionEnter 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.