how can i draw a sprite between 2 touch points with the direction of the sprite facing the direction of the swipe?
ie: draw an arrow sprite between touch began and touch move end with the arrow direction facing touch move end?
how can i draw a sprite between 2 touch points with the direction of the sprite facing the direction of the swipe?
ie: draw an arrow sprite between touch began and touch move end with the arrow direction facing touch move end?
Something like this might do the trick:
using UnityEngine;
using System.Collections;
public class PointArrow : MonoBehaviour
{
public GameObject arrow;
private Vector2 start;
void Update()
{
foreach (Touch t in Input.touches)
{
Vector2 pos = Camera.main.ScreenToWorldPoint(t.position);
if (t.phase == TouchPhase.Began)
{
arrow.transform.position = start = pos;
}
if (t.phase == TouchPhase.Ended)
{
Vector2 dir = pos - start;
arrow.transform.rotation =
Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x));
}
}
}
}