Unity中的触发机制 [英] Trigger mechanism in Unity

查看:120
本文介绍了Unity中的触发机制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我正在创建像《飞扬的小鸟》这样的游戏,我想在玩家经过两个管道之间时触发,以便我可以计算出玩家越过了多少管道.

预先感谢.

解决方案

使用BoxCollider组件创建游戏对象,但不使用渲染器.

缩放BoxCollider,使其包含触发区域.

然后将对撞机设置为触发器,并向其附加脚本,该脚本包含OnTriggerEntered函数中的某些所需功能.

注意:您的玩家游戏对象应具有刚体和对撞机,否则不会记录任何碰撞.

如果您希望此触发器随每个障碍物一起出现,请将其添加到您的障碍物预制物中.

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.

解决方案

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.

这篇关于Unity中的触发机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆