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
0
Question by buxton4life · Aug 27, 2012 at 09:22 AM · javascriptiostouchmultiple

Detecting Multiple Touches on same frame IOS

Hullo Unity world,

I am trying to script code that allows a user to press multiple guiTextures at the same time. Example- The guiTextures are up, left and right. I would like to be able to go left and up at the same time but I am struggling to code in my textures to the code below? :-

  var ball : Transform;
  var ArrowLeft : GUITexture;
  var ArrowRight : GUITexture;
  var ArrowUp : GUITexture;

  function Update() 

  {

 var count : int = Input.touchCount;

 

 for(var i: int = 0;i < count; i++)//for multi touch

 {

     var touch : Touch = Input.GetTouch(i);

 

     if(guiTexture.HitTest(touch.position) && touch.phase == TouchPhase.Began)

     {

         HOW WOULD I IMPLEMENT MY THREE ACTIONS INTO HERE?? :/

     }

 }

 }
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
0
Best Answer

Answer by buxton4life · Aug 28, 2012 at 08:33 PM

  var ArrowLeft : GUITexture;
  var ArrowUp : GUITexture;


 function Update(){

 var count : int = Input.touchCount;

 for(var i: int = 0;i < count; i++)
 
 {
     var touch : Touch = Input.GetTouch(i);
 
     if(ArrowLeft.HitTest(touch.position))
     {
         // code to go left
     }
 
     if(ArrowUp.HitTest(touch.position))
     {
         // code to go up
     }
 
 }
 }
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
avatar image
0

Answer by ScroodgeM · Aug 27, 2012 at 07:03 PM

methinks that changing Input.mousePosition to evt.position in first example will solve your issue

Comment
Add comment · Show 5 · 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 buxton4life · Aug 27, 2012 at 07:05 PM 0
Share

Yes thats right, but I was wondering how to make the second piece of code work like the first but the second would allow two textures to be used at the same time? Any ideas? Thank You.

avatar image ScroodgeM · Aug 27, 2012 at 10:03 PM 0
Share

your question is unclear for me a little.

if(guiTexture.HitTest(touch.position) && touch.phase == TouchPhase.Began)

which texture do you checking here? and how do you want to implement 3 actions based on one texture? is it one texture with all buttons at once or something?

avatar image buxton4life · Aug 28, 2012 at 08:05 AM 0
Share

No sorry, I have three different textures in my scene. One that makes the ball go up and two which make it go left and right. I'm stuck on how to get these three to work in array format so that two of them can be used at the same time. So for example the user could press up and right and the ball would go diagonally North East, though when I try pressing two buttons with the first bit of code it only allows one at a time. Sorry it's hard to explain ha. Thanks again for the reply.

avatar image Seth-Bergman · Aug 28, 2012 at 07:25 PM 1
Share

I've never used HitTest before, but maybe try like this:

 for(var i: int = 0;i < count; i++)
 
 {
     var touch : Touch = Input.GetTouch(i);
 
     if(ArrowLeft.HitTest(touch.position))
     {
         // code to go left
     }

     if(ArrowUp.HitTest(touch.position))
     {
         // code to go up
     }
 
 }

also, keep in $$anonymous$$d that TouchPhase.Began will only refer to the first frame that texture is hit, (which is why I removed it here, but it kind of depends on how your movement is implemented..)

avatar image buxton4life · Aug 28, 2012 at 08:31 PM 0
Share

Thats the one seth it works perfect. All I had to do was put

      var count : int = Input.touchCount;

below the update function i'll post the your answer as an answer now. Thanks Again.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

android touch input 1 Answer

Unity 2D Mobile Game Drawing Mechanic 0 Answers

touch position 2 Answers

Need Help With Unity iOS "touch" Code 2 Answers

Make an object move in the direction of touch 0 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