简体   繁体   English

Unity突破游戏改变球的方向,基于它使用c#进行碰撞所产生的球拍部分

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

I am experimenting with a 2D breakout game (in c#) using Unity 5 and wanted to know how I can change the direction of the ball based on which part of the paddle it made collision with. 我正在尝试使用Unity 5进行2D突破游戏(在C#中),并且想知道如何根据与球拍发生碰撞的那部分来改变球的方向。

For example if the ball touched the left part of the paddle then the ball should go left and if it struck the middle then it should go straight up and if it struck the right side then go right. 例如,如果球碰到了桨的左部,那么球应该向左移动;如果击中了中部,那么球应该直线上升;如果击中了右侧,那么就向右移动。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM