Created
June 5, 2019 16:05
-
-
Save Creta5164/581c769637c9edded8d0eb1a63423b49 to your computer and use it in GitHub Desktop.
Showing touch on Unity editor view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Author
Creta5164
commented
Jun 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment