- Home /
multitouch problem
hi guys, i am banging my head with this for a while i could really use some help...i think it is trivial for experienced ones
here is what i am trying to do.
i have two buttons and for each of those two buttons i have three states
enum buttonState{NOT_ACTIVE,AIM,FIRE}
so both buttons should be able to aim and fire. if left button was touched first then it will have aim state and second button if touched will fire. if first button to be touched is right then right will aim and left will fire if touched. if none buttons are touched then both buttons will have not_active state.
i managed to get aim with left and fire for right but it is hard coded, i can not manage to figure out how to generalize the part where touchCount==2 to figure out what is Input.GetTouch(0) and what is Input.GetTouch(1). i guess i will have to track fingerID but i do not know how to implement it
here is the code for case of two touches
//two touches
if(Input.touchCount>1){
if(LeftButton.GetState()==ButtonState.AIM){
if(RightButton.GetInputRect().Contains(Vector2(Input.GetTouch(0).position.x,Screen.height-Input.GetTouch(0).position.y))){
RightButton.SetButtonState(ButtonState.FIRE);
}
}
if(RightButton.GetButtonState()==ButtonState.AIM){
if(LefButton.GetInputRect().Contains(Vector2(Input.GetTouch(1).position.x,Screen.height-Input.GetTouch(1).position.y))){
LeftButton.SetButtonState(ButtonState.FIRE);
}
}
}
any help is appreciated!
Answer by Wumpee-2 · Jan 01, 2012 at 04:33 PM
I'm not sure if you'd need to track touches or finger id. You could probably get away with something like the following:
if (Input.touchCount > 1)
{
for (int i = 0; i < Input.touchCount; ++i)
{
if (LeftButton.GetState() == ButtonState.AIM)
{
if (RightButton.GetInputRect().Contains(Vector2(Input.GetTouch(i).position.x, Screen.height - Input.GetTouch(i).position.y)))
{
RightButton.SetButtonState(ButtonState.FIRE);
}
}
else if(RightButton.GetButtonState() == ButtonState.AIM)
{
if (LeftButton.GetInputRect().Contains(Vector2(Input.GetTouch(i).position.x, Screen.height - Input.GetTouch(i).position.y)))
{
LeftButton.SetButtonState(ButtonState.FIRE);
}
}
}
}
but if you are using Touchphases in if condition this will check for all the touches.. which is not needed.. it will require fingerID to resolve the issue.