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 ALAN! · Feb 17, 2013 at 09:49 PM · androidtouchtouchphase

TouchPhase won't return anything but Began

I'm using Unity 4, working on an Android game. When I put the following code at the beginning of my Update function:

 myGUI.text =  Input.touches[0].phase + "";

it works perfectly, prints Moved when I move my finger, prints Stationary when I don't, etc. myGUI is a GUIText object.

But when I put that same snippet of code after this code:

         if (Input.touches[0].phase == TouchPhase.Began) {
             if (Input.touches[0].position.y < scrnW/2) {
                 rightTouchNum = 1; }
             else if (Input.touches[0].position.y > scrnW/2) {
                 leftTouchNum = 1;  }
             }
 
         else if (Input.touches[1].phase == TouchPhase.Began) {
             if (Input.touches[1].position.y < scrnW/2) {
                 rightTouchNum = 2;    }
             else if (Input.touches[1].position.y > scrnW/2) {
                 leftTouchNum = 2;  }
             }

It won't return anything but Began. Why is this?? How can I possibly be altering the results of touchphase with these if statements? rightTouchNum, leftTouchNum and scrnW are just integers.

I've attached my code for good measure. Thank you!

[1]: /storage/temp/7988-touchcube.js.zip

touchcube.js.zip (1.3 kB)
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 ALAN! · Feb 18, 2013 at 06:35 AM

Figured it out! Turns out i'm a big old dummy. Here's the correct code

         if(Input.touchCount > 0)
         {
         
         //When finger is touched down, determines if left or right:
         if (Input.touches[0].phase == TouchPhase.Began) {
             if (Input.touches[0].position.y < scrnW/2) {
                 rightTouchNum = 1; }
             else if (Input.touches[0].position.y > scrnW/2) {
                 leftTouchNum = 1;  }
             }
                 
                 
             if (Input.touchCount >1) {    
         if (Input.touches[1].phase == TouchPhase.Began) {
             if (Input.touches[1].position.y < scrnW/2) {
                 rightTouchNum = 2;    }
             else if (Input.touches[1].position.y > scrnW/2) {
                 leftTouchNum = 2;  }
             }
             }
         }
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 Paulo-Henrique025 · Feb 17, 2013 at 10:08 PM

I can't see anything wrong with your code, just for testing try this:

 switch(Input.touches[0].phase)
         {
             case TouchPhase.Began:
             break;
             
             case TouchPhase.Moved:
             break;
             
             case TouchPhase.Ended:
             break;
         }
Comment
Add comment · Show 3 · 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 ALAN! · Feb 17, 2013 at 10:33 PM 0
Share

Still having the same problem. If I put that code you gave me before that chunk of code I posted, all three cases are activated at the appropriate time. But I post it after, only the first case is ever activated

avatar image Paulo-Henrique025 · Feb 17, 2013 at 10:38 PM 0
Share

Send an email to support, your issue seems rather uncommon.

avatar image ALAN! · Feb 17, 2013 at 10:48 PM 0
Share

Ok, thanks for the advice! I emailed them my problem. If anyone else has any ideas or would like to try my code and see how it works for them, that would be pretty rad guys

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

10 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

Related Questions

Disable touch while object moving back to start position 0 Answers

TouchPhase doesn't end when player swipes off screen 1 Answer

Short question: If my app runs without any problems on Android, should it run without any problems on iOS? 1 Answer

How to touch, move and rotate 3D objects in XZ? 1 Answer

TouchPhase not firing correctly - Android 3 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