- Home /
How can I check if a certain Touch exists?
I can't find a way to check if a certain touch exist script below "foreach (Touch touch in Input.touches) {
if (some requierments)
{
follow = true;
followTouch = touch;
}
}"
so my code just make an object follow my touch(I have stored the Touch in a variable 'touch') and once the touch doesn't exists anymore I want it to go back to his native position(this is the parent's position 'transform.parent.transform.position') Things I have tried 1)
if (Input.touchCount < 1)
{
//doesn't work because you often have multiple touches
}
2)
if (touch != null)
// but i can't compare a touch value and 'null'
3) there neither is a touch.exist to use
Questions so what's a way to check if a touch is 'alive' or is there maybe a way to find the index of a touch (while the touch is stored in a variable)
Answer by salamander555 · Apr 03, 2017 at 07:23 AM
Going to answer my own question here just use this if ('TouchVariable'.phase == TouchPhase.Ended) { }
Oh so you wanted the "some requirement" filled in, now I understand your question.
Answer by gameplay4all · Apr 02, 2017 at 03:47 PM
Not really sure if I understand your question, but instead of saving the touch; save the index! So then you can do things like,
if(Input.touchCount > followTouch){
//Do stuff here with Input.GetTouch(followTouch)
}
else{
//The finger is let go.
follow = false;
followTouch = -1;
}
So followTouch is now an int :)
Hope this gets you further!
-Gameplay4all
EDIT:
So you have this piece of code:
foreach (Touch touch in Input.touches) {
if (some requierments)
{
follow = true;
followTouch = touch;
}
}
Change it to:
for (int i = 0; i < Input.touchCount; i++) {
if (some requierments with Input.GetTouch(i) )
{
followTouch = i;
}
}
Now you can use the code I mentioned in my original answer :)
And where you have followTouch declared, change it to an int.
Can you explain in word what you put here bc i don't really get what you are doing
See my edited answer, if you want help with objects tracking Touches: there are plenty of answers/tutorials for that already. Like this.
Your answer
Follow this Question
Related Questions
I can't use more that two buttons at the time. How do I change that? 0 Answers
GameObject dropping and laging while dragging on Android 2 Answers
Detect Android device touch points amount. 0 Answers
Unusual multitouch behavior (Android) 3 Answers
Need Android Help - How do I click and mouseover a 3d object? 1 Answer