Trigger mechanism in Unity

三世轮回 提交于 2019-12-24 23:06:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!