问题
Lets say I'm creating a game like Flappy bird, I wanted to trigger when ever the player passes between two pipes so that i can count how many pipes dose the player crossed.
Thanks in Advance.
回答1:
Create a gameobject with a BoxCollider
component, but no renderer.
Scale the BoxCollider such that it encompasses your trigger area.
Then set the collider as a trigger and attach a script to it that contains some desired functionality in the OnTriggerEntered
function.
Note: your player gameobject should have a rigid body and collider attached to it, or no collisions will be recorded.
If you wish for this trigger to appear with every obstacle, add it to your obstacle prefab.
来源:https://stackoverflow.com/questions/25450414/trigger-mechanism-in-unity