- Home /
Problem in multi touch
Hello,
I have two code for multi touch and according to my understanding both codes should behave same but in actual they are behaving different.I have defined a Rect which will show a texture at the bottom of screen.
Rect jump_rect;
void Start ()
{
jump_rect= new Rect(Screen.width*0.4f,Screen.height*0.85f,Screen.width*0.1f,Screen.height*0.1f);
}
Here is 1st code
if(Input.touchCount>0)
{
for(int i=0;i< Input.touchCount;i++)
{
Vector3 inputGuiPosition = Input.GetTouch(i).position;
inputGuiPosition.y = Screen.height - inputGuiPosition.y;
if(jump_rect.Contains(inputGuiPosition))
{
//do Something
}
}
}
1st code is working fine. jump_rect position and touch position are aligned and working fine.But problem lies in 2nd code and according to my understanding 2nd code should behave like 1st code.
Here is 2nd code
if(Input.touchCount>0)
{
for(int i=0;i< Input.touchCount;i++)
{
Touch touch=Input.GetTouch(i);
touch.position.y=Screen.height-touch.position.y;
if(jump_rect.Contains(touch.position))
{
//Do something
}
}
}
But in 2nd code jump_rect and touch position are not aligned. When i click at top of screen jump_rect.Contains(touch.position) returns true.
please tell me whats the difference between 1st and 2nd code.. and why jump_rect.Contains(touch.position) is returning true when i click top of screen.
Try inspecting the values yourself by printing them out
Debug.Log(jump_rect+" "+inputGuiPosition);
and
Debug.Log(jump_rect+" "+touch.position);
Your answer
Follow this Question
Related Questions
Multi-touch problem in a 2 player pong game 2 Answers
Can't move and fire at the same time! 0 Answers
define touch area 2 Answers
Can't solve hitbox issues in mobile game 1 Answer
touch controls help dragging a charater 0 Answers