Physics and GUI Events
Understand the usage of physics and GUI event functions that Unity offers.
We'll cover the following
Physics events
Collisions reported by the physics engine come under the umbrella of physics events. The events responsible for detecting changes to such a collision are OnCollisionEnter
, OnCollisionStay
, and OnCollisionExit
. For Colliders that have the “Is Trigger” property turned on, the equivalent events for them are OnTriggerEnter
, OnTriggerStay
, and OnTriggerExit
.
The OnCollisionEnter
event
The OnCollisionEnter
event is fired whenever a Collider begins overlapping with another Collider for the first time.
In the last lesson, we edited the Platform.cs
script such that the platform’s color changes when we hit the spacebar. Now, we’ll give a little impulse to our ball when it collides with the platform while it’s pink. The highlighted portion in the script below will accomplish this task.
Get hands-on with 1400+ tech skills courses.