- Home /
A touch'es state is always Began and the position doesn't change
So with this script i'm trying to get the phase and position of the newest touch but for some reason the phase always returns "Began" and the position only updates at the exact frame i actually begin the touch. The print("touching") part works correctly though. Am i missing something?
public Touch usedTouch;
private void Update()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
usedTouch = touch;
print("touching");
}
}
print(usedTouch.phase + " " + usedTouch.position);
}
Answer by Bunny83 · Jan 07, 2018 at 10:15 AM
Uhm, the Touch struct is a struct. Once you aquired the information it will keep static and of course won't change on it's own. You have to read the new state by iterating the touches array each frame. To identify a certain touch you have to use the fingerId of the touch.
So storing a Touch in a member variable is pretty useless. Store the fingerID in a variable so you can identify the same touch again next frame.
That's actually exactly what i did after posting the question and it works 100%! And now thanks to your answer i also know why my previous approach didn't work, thanks!
Your answer
Follow this Question
Related Questions
check touch position 2 Answers
How to show and hide an image by swiping 0 Answers
Reset touch Vector after movement 2 Answers
Unity Touch Help! 0 Answers