Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Robindoo · Jul 26, 2010 at 03:04 AM · iphonetouch

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 alt text

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");
             }
         }
     }
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

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.

==

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Robindoo · Jul 27, 2010 at 05:56 AM 0
Share

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.

avatar image
-1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges