Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道如何在 C# 中创建一个函数,当我的鸟游戏对象接触到地面或屏幕顶部时调用该函数。我希望它在发生这种情况时结束游戏。我尝试将bird.position.x 与屏幕高度进行比较,但没有奏效,我希望你有另一种方法。谢谢
您正在寻找的功能称为 OnTriggerEnter2D
void OnTriggerEnter2D(Collider other) { if(other.gameObject.tag == "Floor") //You lost }
您需要将此函数放在小鸟游戏对象的 Scrip 中,然后将碰撞器添加到小鸟和地板,并为地板分配标签,以便您可以在 OnTriggerEnter2D 内部检查小鸟是否撞到地板上。