using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bola : MonoBehaviour
{
Vector2 posInicial, posFinal, direcao;
private float touchTimeInicial, touchTimeFinal, touchTime;
public float forcaLancamento = 0.5f;
private void Update()
{
if(Input.touchCount && Input.GetTouch(0).phase == TouchPhase.Began)
{
touchTimeInicial = Time.time;
posInicial = Input.GetTouch(0).position;
}
if(Input.touchCount && Input.GetTouch(0).phase == TouchPhase.Ended)
{
touchTimeFinal = Time.time;
touchTime = touchTimeFinal - touchTimeInicial;
posFinal = Input.GetTouch(0).position;
direcao = posFinal - posInicial;
GetComponent<Rigidbody2D>().AddForce(direcao / touchTime * forcaLancamento);
}
}
}