first, a new cube, which itself has its own Collider collider, as shown in Figure
To use trigger to detect object entry, you need to tick the IS trigger option
Collision detection trigger trigger is different from the collision detector collision, which can be unaffected by physical effects, some can penetrate the area of the collision detection, you can use the trigger for collision detection
Common methods are as follows:
When Ontriggerenter enters
When Ontriggerexit left
Ontriggerstay in time
The same as the collision detector collision also has 3 methods:
Oncollisionenter
Oncollisionexit
Oncollisionstay
Here we need to add an end line to the runway mechanism, so use a penetrating collision detection trigger trigger
The code is as follows:
1 2 3 4 5
|
void Ontriggerenter (Collider Collider) { Print (collider. Gameobject. Name + ":" + time. Time);
} |
Ontriggerenter the parameter passed in must be collider, so the object that can trigger the function must have a collider build. Here we're using the character controller character controllers with Collider build
The role name and system time are printed whenever a character hits a line
Next we use the collision detector collision to perform a collision detection.
First, cancel the is on the object being hit.