Scripting with the Physics system
In this section, we will explore how to interact with the Physics system via C# scripts. Similar to the previous section, we will also introduce the C# methods for colliders, triggers, and Rigidbodies, respectively. We will start with the C# methods for colliders.
Collision methods
When a collider is not used as a trigger, collisions between Rigidbodies still occur. These three methods are called when a collision occurs, and the parameter type is the Collision class, which provides some information to describe the collision, such as the contact point and the impact velocity of the collision.
OnCollisionEnter
The first method is OnCollisionEnter
, which is called when this collider begins to touch another collider. It is useful when you want to make this object be affected by a physical collision, but also want to perform some game logic when the collision occurs. For example, when a bullet hits the target in a game, a corresponding explosion...