如何通过触摸在屏幕上拖动手指来移动3D对象



我想通过触摸来移动对象拖动手指通过屏幕意味着对象应该沿着手指的方向我在Play Store上找到了一个游戏,在这个游戏中,球通过触摸来左右移动,这正是我游戏中想要做的我的游戏链接:-https://play.google.com/store/apps/details?id=com.ketchapp.hop

最简单的方法是将玩家手指在屏幕上的位置设置为世界点,并将该世界点设置为Vector3。将球移动到世界点Vector3(假设你想使用一个速度移动,否则只使用.position(。

//Variables
public transform ball;
public float speed = 10f;
//i do not know about touch screen controls. this is something i will link to below!
//Get Touch Position
Vector3 worldTouchPos = screenTouchPos; //worldTouchPos = the touch position in world space, and the screenTouchPos is the touch position on the screen ( so a value between 0 and 1 in both x and y).
//Ball Movement
ball.position = Vector3.MoveTowards(ball.position //pos to move from\ ,worldTouchPos //pos to move to\, speed);

触摸控制链接到YT视频:Brackeys视频,/你想看的其他视频!!!

最新更新