Мне нужно, чтобы объект переместился в положение касания пользователя.
Это мой подход к решению проблемы:
public float speed = 1.5f;
public Rigidbody2D ball;
bool hasMoved = false;
Vector2 point;
void Start()
{
ball.GetComponent<Rigidbody2D>();
ball.gravityScale = 0;
Vector2 point = Vector2.zero;
}
void Update()
{
if(Input.GetMouseButtonUp(0) && !hasMoved)
{
hasMoved = true;
Vector2 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 direction = new Vector2(point.x - transform.position.x, point.y - transform.position.y);
StartCoroutine(Lancio(direction));
ball.gravityScale = 80;
}
}
IEnumerator Lancio(Vector2 direction)
{
ball.AddForce(direction.normalized * speed);
yield return new WaitForSeconds(0.03f);
}
Есть идеи?