Unity breakout 游戏根据球拍的哪一部分使用 c# 进行碰撞来改变球的方向

Unity breakout game change direction of ball based on which part of the paddle it made with collision using c#

我正在使用 Unity 5 试验 2D 突破游戏(在 c# 中),想知道如何根据球拍与球拍的哪个部分发生碰撞来改变球的方向。

例如,如果球碰到球拍的左侧部分,那么球应该向左移动,如果它击中了球拍的中间部分,那么它应该直接向上移动,如果它击中了球拍的右侧,那么它应该向右移动。

您可以在桨的每一侧制作 4 个不同的 box collider 2d 作为子对象,并向它们添加 OnCollisionEnter2d() 方法,您可以在其中应用您的机制