C# 统一-使角色朝着触摸/拖动位置行走?在三维空间中?
好的,我有一个为iOS构建的3D Unity游戏,其中将实现这些控件(以第一人称射击方式):C# 统一-使角色朝着触摸/拖动位置行走?在三维空间中?,c#,unity3d,physics,game-development,C#,Unity3d,Physics,Game Development,好的,我有一个为iOS构建的3D Unity游戏,其中将实现这些控件(以第一人称射击方式): 摄影机紧跟在角色后面 手指停留在屏幕上使角色行走,手指向上使其停止 这就是问题所在:无论用户在哪里开始触摸屏幕,无论他们朝哪个方向拖动(向前、向后、左右),角色都会无限期地朝那个方向行走 这一定已经完成了,但我在任何地方都找不到任何东西。我将相机作为角色的子角色,因此这已得到处理,但对于角色移动,我所拥有的只是: void Update() { if (Input.touchC
void Update()
{
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector3 target = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -10f));
transform.Translate(Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime) - transform.position);
}
这不符合需要。我能在这里做什么呢?你可以试着使用任何一种UI操纵杆() 并访问其参数,如下所示:
public class TestMovement : MonoBehaviour
{
public float Speed;
public FloatingJoystick Joystick; //Set in the inspector, prefab from the asset
private void Update()
{
transform.Translate(new Vector2(Joystick.Horizontal, Joystick.Vertical) * Speed * Time.deltaTime);
}
}
例如,您可以尝试使用任何UI操纵杆之王() 并访问其参数,如下所示:
public class TestMovement : MonoBehaviour
{
public float Speed;
public FloatingJoystick Joystick; //Set in the inspector, prefab from the asset
private void Update()
{
transform.Translate(new Vector2(Joystick.Horizontal, Joystick.Vertical) * Speed * Time.deltaTime);
}
}