Суть в том, чтобы перемещать игрока пальцем, при этом не касаясь его самого. И он не должен телепортироваться к точке касания. Если не совсем понятно, попробуйте скачать игры, приведенные сверху.
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Transform player;
public float speed = 5000f;
private bool touchStart = false;
private Vector2 offset;
private Vector2 point;
private Vector2 pos;
private void Awake()
{
player = transform;
}
private void FixedUpdate()
{
if(Input.GetMouseButton(0))
{
touchStart = true;
pos = player.position;
point = Camera.main.ScreenToWorldPoint( new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z) );
offset = point - pos;
}
else
{
touchStart = false;
}
if (touchStart)
{
transform.position = point + offset;
}
}
}
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Transform player;
public float speed = 5000f;
private bool touchStart = false;
private Vector2 offset;
private Vector2 point;
private Vector2 pos;
private void Awake()
{
player = transform;
}
private void FixedUpdate()
{
if(Input.GetMouseButton(0))
{
touchStart = true;
pos = player.position;
point = Camera.main.ScreenToWorldPoint( new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z) );
offset = point - pos;
}
else
{
touchStart = false;
}
if (touchStart)
{
transform.position = point + offset;
}
}
}