【发布时间】:2020-10-23 14:03:46
【问题描述】:
我想通过触摸来移动对象 在屏幕上拖动手指意味着对象应该跟随手指的方向 我在 Play 商店中找到了一个游戏,游戏中的球通过触摸它来左右移动,这正是我想要在我的游戏中制作的内容 我的游戏链接:- https://play.google.com/store/apps/details?id=com.ketchapp.hop
【问题讨论】:
标签: c# android visual-studio unity3d touch
我想通过触摸来移动对象 在屏幕上拖动手指意味着对象应该跟随手指的方向 我在 Play 商店中找到了一个游戏,游戏中的球通过触摸它来左右移动,这正是我想要在我的游戏中制作的内容 我的游戏链接:- https://play.google.com/store/apps/details?id=com.ketchapp.hop
【问题讨论】:
标签: c# android visual-studio unity3d touch
最简单的做法是将玩家手指在屏幕上的位置设置为一个世界点,然后将该世界点设置为 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 video,/ The Other video that you want to watch!!!
【讨论】: