【问题标题】:How To Move 3D Object By touch Dragging The Finger On the screen如何通过触摸在屏幕上拖动手指来移动 3D 对象
【发布时间】:2020-10-23 14:03:46
【问题描述】:

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

【问题讨论】:

    标签: c# android visual-studio unity3d touch


    【解决方案1】:

    最简单的做法是将玩家手指在屏幕上的位置设置为一个世界点,然后将该世界点设置为 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!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多