- Home /
Multitouch problem in Unity iPhone
I am having some issues with the multitouch in Unity iPhone. I want to apply the following script onto two objects such that I can move my both object at the same time with two different fingers. But whenever I touch one object, other object wont work.
Attached is a screen shot to give a clear understanding of what I am trying to do. I want to rotate the two circles at the same time using two different fingers. I tried having both access from the same script and having two separate scripts, both doesnt solve my problem
var Palette : GameObject;
var prevVecX : float;
var diff: float;
var spinSpeed : int = 360;
function Update ()
{
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
for (var i = 0; i < iPhoneInput.touchCount; ++i)
{
if (Physics.Raycast (ray, hit, 1000))
{
if ( hit.collider == Palette.collider )
{
if (iPhoneInput.GetTouch(i).phase == iPhoneTouchPhase.Began)
{
Debug.Log("U touched right");
}
if (iPhoneInput.GetTouch(i).phase == iPhoneTouchPhase.Stationary)
{
prevVecX = iPhoneInput.GetTouch(i).position.x;
}
if (iPhoneInput.GetTouch(i).phase == iPhoneTouchPhase.Moved)
{
diff = iPhoneInput.GetTouch(i).position.x - prevVecX;
if(diff >= 0)
{
Palette.transform.Rotate(Vector3.up * Time.deltaTime * spinSpeed);
}
else
{
Palette.transform.Rotate(Vector3.up * Time.deltaTime * -spinSpeed);
}
}
if (iPhoneInput.GetTouch(i).phase == iPhoneTouchPhase.Ended)
{
Debug.Log("Released");
}
}
}
}
}
Answer by equalsequals · Jul 26, 2010 at 01:28 PM
This is because at any given time you only have one raycast when you should have multiple, one for each touch.
The result you're seeing is because of the single raycast, and that you're using an incorrect parameter in Input.mousePosition. It'll work for your first index in the stack (where you touch first) but the condition will never be true for the second.
Here's the part that matters:
for (var i = 0; i < iPhoneInput.touchCount; ++i) { var hit : RaycastHit; //I currently don't have my iPhone docs handy so that might not be the way to access the position of your touch var ray = Camera.main.ScreenPointToRay (iPhoneInput.GetTouch(i).position);
//...
Hope that helps.
==
Thanks. it really did work. Just started out with developing a game for iPhone using Unity as part of my school project so I didn't really have much idea how Unity works.
Answer by achingupta87 · May 10, 2012 at 07:03 AM
I m also try to move two cube simultaneously with two finger . I m getting the same problem. I m not expert in unity. can u share me sample code which is working for multiple touch???
Thanks In advance
Achin
Your answer
![](https://koobas.hobune.stream/wayback/20220613065644im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
All objects response to one touch 1 Answer
translating a touchDeltaPosition from the y axis to z axis 1 Answer
Analogue OnMouseUp for iOS(Unity iPhone) 0 Answers
Touches don't respond correct 2 Answers
Taping in UnityIphone. URGENT! 2 Answers