Touch in Phase ended
Hi there I have a sprite on screen . i use two separate code for TouchPhase.Began and TouchPhase.Ended . i like to run code when i touch up on sprite ( in TouchPhase.Ended ) but when i touching other position on screen and move my finger on sprite and then up my code get run .
if (Input.touchCount == 1)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
Vector2 touchp = touchPos ;
if (Input.GetTouch (0).phase == TouchPhase.Began) {
touchp = Input.GetTouch (0).position;
}
if (coll2D == Physics2D.OverlapPoint (touchPos) ) {
if (Input.GetTouch (0).phase == TouchPhase.Began) {
SpRenderer.color = new Color (1f, 1f, 1f, 0.7f);
}
if (Input.GetTouch (0).phase == TouchPhase.Ended && coll2D == Physics2D.OverlapPoint (touchp)) {
if (transform.position.y == StartPosition)
CanMoveUp = true;
if (transform.position.y == TargetPosition)
CanMoveDown = true;
SpRenderer.color = new Color (1f, 1f, 1f, 1f);
}
} else if (coll2D != Physics2D.OverlapPoint (touchPos)) {
SpRenderer.color = new Color (1f, 1f, 1f, 1f);
}
}
It's better not to use a picture for the code. It makes it harder for someone who wants to cut and paste to test it, and takes longer to load on slow connections. Better to use just text with code formatting.
Also, I moved this into the HelpRoom, since you're really asking for personal help fixing your script. You can post directly there by selecting it in the dropdown when you ask a Q.
Your answer
Follow this Question
Related Questions
Sprite occasionally moving to left when dragging to right 0 Answers
2D touch - Why is this movement so jittery? 1 Answer
Enhanced touch 0 Answers
How to separate a Tap from a Swipe? 0 Answers
How do I make a rigid body move towards position of touch 0 Answers