問題描述
如何在 Unity 中進行沒有物理的碰撞檢測? (How to have collision detection without physics in Unity?)
我正在製作一個簡單的 Unity 2D 遊戲。其中有三個遊戲對象 ‑ 1) 地面(長矩形) 2) 玩家(正方形) 3) 硬幣(圓形) 目前我是在所有三個上使用對撞機。這些碰撞器幫助玩家保持在地面上,當玩家與硬幣碰撞時,我會增加分數。 但問題是,當玩家與硬幣碰撞時,它的行為就像硬幣是物理物體一樣,它會停止玩家。我不想要這個 我希望當玩家與硬幣碰撞時,它們之間沒有物理交互 我嘗試了一件事 ‑ 將玩家和硬幣中的碰撞器切換為 isTrigger,但在在這種情況下,玩家和地面以應有的方式進行交互(玩家從地面跌落)。
參考解法
方法 1:
Make the interactable objects triggers. That way, you can interract with them, without obstracting your path. To do that, go to the collider Component on the inspector and check the "Is Trigger" checkmark. Then, go to your scripts and instead of the event OnColliderEnter use the event OnTriggerEnter