Trigger mechanism in Unity

2019-08-24 13:00发布

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.

This is the Trigger i wanted

Thanks in Advance.

1条回答
放我归山
2楼-- · 2019-08-24 13:28

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.

查看更多
登录 后发表回答