Perform Task Simultaneously Through Touch??
I have divided the screen in 2 parts left and right. When i touch on the left part the object moves forward. When i touch the right part of the screen the object jumps. I want to perform both these task simultaneously or together at the same time. When i touch on both parts of the screen both functions should run simultaneously. How can i do that?
if(Input.touchCount == 2)
{
Touch[] touches = new Touch[2];
touches [0] = Input.GetTouch (0); // Gets the Frist touch on the screen
touches [1] = Input.GetTouch (1); // Gets the Secind touch on the screen
if (touches[0].position.y > Screen.height-200 && touches[1].position.y < Screen.height/2-100)
{
// I want to perform both the touches functions here
}
It's probably more complicated than that. The way you have it is for when when someone touches left then right together.
What should you do if someone touches only the RIGHT side and moves? Same thing but only the left side? The problem is, touch[0] could be the left or right side. Then, you have to worry about someone touching left, then right, then letting go of left. That would make Touch[0] switch from left to right. The way to do is using the touch numbers it gives you.
A trick, can use int leftTouchNum=-1, rightTouchNum=-1;
. If someone touches the right side only, you'd have left=-1, right=0. But the coding is tricky.