Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Lemo76 · Oct 11, 2015 at 12:34 PM · erroriostouchdetectionlogic

[iOS] Multitouch not working

So I've started developing for iOS and I've run into a few troubles.

I've got four boolean variables (player1for, player1back, player2for, player2back) , all four of which can be toggled on and off independently.

They turn on when someone touches their region (ie. x>0 and y>0, or x0, or x<0 and y<0, or x>0 and y<0).

This means that if I have all regions pressed at the same time, all four booleans will be on. Say I touch only three regions, those regions (with their respective booleans) will be on, whilst the other region will be off.

Get the idea?

So, here's the code:

 nTouches = Input.touchCount;
 if (nTouches > 0) {
 if (isHandheld) {
             for(int i = 0; i < nTouches; i++)
             {
                 Touch touch = Input.GetTouch (i);
                 touchPos = new Vector3 (touch.position.x - Screen.width/2,0, touch.position.y - Screen.height/2);
                 if (touchPos.x > 0 && touchPos.z > 0) {
                     moveLord.player2for = true;
                 } else {
                     moveLord.player2for = false;
                 }
                 if (touchPos.x > 0 && touchPos.z < 0) {
                     moveLord.player2back = true;
                 } else {
                     moveLord.player2back = false;
                 }
                 if (touchPos.x < 0 && touchPos.z > 0) {
                     moveLord.player1back = true;
                 } else {
                     moveLord.player1back = false;
                 }
                 if (touchPos.x < 0 && touchPos.z < 0) {
                     moveLord.player1for = true;
                 } else {
                     moveLord.player1for = false;
                 }
                 DEBUGGER2.text = "[" + touchPos.x + "," + touchPos.y + "]";
             }
         }
 }

So what's the problem? Well, I can never have more than one region on (i.e. if player1back is true, player1for, player2back, and player2for is false) at the same time. It only recognises the most 'recent' press.

I'm sure this is just some silly logic error, but right now I'm not exactly seeing it.

I greatly value your opinion, so thanks!

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

1 Reply

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

Answer by Lemo76 · Oct 13, 2015 at 05:31 AM

Found the solution:

     if (isHandheld) {
         moveLord.player1back = false;
         moveLord.player2for = false;
         moveLord.player2back = false;
         moveLord.player1for = false;
         for(int i = 0; i < nTouches; i++)
         {
             Touch touch = Input.GetTouch (i);
             touchPos = new Vector3 (touch.position.x - Screen.width/2,0, touch.position.y - Screen.height/2);
             if (touchPos.x > 0 && touchPos.z > 0) {
                 moveLord.player2for = true;
             }
             if (touchPos.x > 0 && touchPos.z < 0) {
                 moveLord.player2back = true;
             }
             if (touchPos.x < 0 && touchPos.z > 0) {
                 moveLord.player1back = true;
             }
             if (touchPos.x < 0 && touchPos.z < 0) {
                 moveLord.player1for = true;
             }
         }

The 'else' statements were the problem + I had to turn them all off on the start of an iteration.

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

35 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

How to check if a variable contains a Touch? 1 Answer

how do i use touch.Position 1 Answer

Drawing lines between two touch positions? 4 Answers

Control the camera with a half of the touch screen 0 Answers

iOS and android support for detecting if app has been rated from within Unity 1 Answer


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