• 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
Question by POLYGAMe · Sep 17, 2012 at 10:17 AM · androidiostouchgui texturemulti

Multi touch not working - What's wrong with this code?

Hi there,

I'm trying to get the Android/iOS controls up and running for my racing game, now that the desktop version is complete... I'm having issues with the multi-touch. For some reason, when I try steering, it stops accelerating until I release the steering button again. Probably somet$$anonymous$$ng simple, I'm new to t$$anonymous$$s touch stuff... any ideas?

EDIT: New code - multi-touch working but buggy - bools stay activated etc, so car tends to all of a sudden veer off the road or stop accelerating.

 function OnGUI()
 {
     for (var i = 0; i < Input.touchCount; ++i) 
     {
         if (Input.GetTouch(i).phase != TouchPhase.Ended && Input.GetTouch(i).phase != TouchPhase.Canceled)
         {
             if (GasButton.HitTest(Input.GetTouch(i).position))
             {
                 bGasButtonPressed = true;
             }
             
             if (TurnLeft.HitTest(Input.GetTouch(i).position))
             {
                 bLeftButtonPressed = true;
             }
             
             if (TurnRight.HitTest(Input.GetTouch(i).position))
             {
                 bRightButtonPressed = true;
             }
         }
         else
         {
             bGasButtonPressed = false;
             bLeftButtonPressed = false; 
             bRightButtonPressed = false;
         }
     }
 }
Comment

People who like this

0 Show 5
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 PAEvenson · Sep 17, 2012 at 12:09 PM 1
Share

If you have 2 touches. Then lift one up, your else is going to trigger setting everything to false.

avatar image POLYGAMe · Sep 17, 2012 at 12:57 PM 0
Share

Hi Fattie, I was using that instead of TouchPhase.Stationary as if the player moves their finger a bit, that would cancel it, no?

avatar image POLYGAMe · Sep 17, 2012 at 01:05 PM 0
Share

@PAEvenson: Haha, that'll learn me to code while I'm tired and sick :P

avatar image Fattie · Sep 17, 2012 at 02:31 PM 0
Share

no, just completely leave out the line that says "If (Input...". just go immediately to the three hit text clauses. cheers !

avatar image POLYGAMe · Sep 18, 2012 at 12:41 AM 0
Share

Oh really? I'll try that now. Thanks again!

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Fattie · Sep 17, 2012 at 12:05 PM

Hello! Your general programming mistake here is ----->

You have to do t$$anonymous$$s part FIRST .............

  bGasButtonPressed = false;
  bLeftButtonPressed = false; 
  bRightButtonPressed = false;

and ONLY THEN do t$$anonymous$$s part,

for (var i = 0; i < Input.touchCount; ++i) .. and onwards

try it !

Secondly, be sure to answer the Q. i pose in the comment. Hope it helps so far.

Comment
POLYGAMe

People who like this

1 Show 2 · 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 POLYGAMe · Sep 17, 2012 at 12:52 PM 0
Share

AAAAAAAHHHH!!!!!

Thank you!!!! It wooooorks!!!!!!

avatar image Fattie · Sep 17, 2012 at 02:29 PM 0
Share

LOL kick ass

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 People are following this question.

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

Related Questions

Make an object move in the direction of touch 0 Answers

Having an issue with getting my touch controls working 0 Answers

Touch joystick tutorials ? 0 Answers

android touch input 1 Answer

iOS - Mutlitouch Count 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