Skip to content

Instantly share code, notes, and snippets.

@Creta5164
Created June 5, 2019 16:05
Show Gist options
  • Save Creta5164/581c769637c9edded8d0eb1a63423b49 to your computer and use it in GitHub Desktop.
Save Creta5164/581c769637c9edded8d0eb1a63423b49 to your computer and use it in GitHub Desktop.
Showing touch on Unity editor view.
public class TouchViewer : MonoBehaviour
{
/// <summary>
/// Half-size of cross-hair
/// </summary>
public float size = 25;
/// <summary>
/// How longer lives trails and cross-hairs
/// </summary>
public float delayScale = 2f;
void LateUpdate()
{
if (Input.touches != null && Input.touches.Length > 0)
Array.ForEach(Input.touches, ShowTouch);
}
private void ShowTouch(Touch point) {
Vector2 trail = point.deltaPosition;
Vector2 position = point.position;
Color? color = null;
switch (point.phase) {
case TouchPhase.Began: color = Color.green; break;
case TouchPhase.Stationary:
case TouchPhase.Moved: color = Color.cyan; break;
case TouchPhase.Ended: color = Color.red; break;
case TouchPhase.Canceled: color = Color.yellow; break;
}
if (color.HasValue) {
float time = point.deltaTime * delayScale;
//Trail
Debug.DrawLine(position, position - trail, color.Value, time);
//Cross-hair
Debug.DrawLine(position + Vector2.left * size, position + Vector2.right * size, color.Value, time);
Debug.DrawLine(position + Vector2.up * size, position + Vector2.down * size, color.Value, time);
}
}
}
@Creta5164
Copy link
Author

touch debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment