Sai
Sai

Reputation: 15718

Trigger mechanism in Unity

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.

Upvotes: 0

Views: 240

Answers (1)

Nick Udell
Nick Udell

Reputation: 2491

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.

Upvotes: 3

Related Questions