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
2
Question by unityRookie · Feb 24, 2012 at 11:45 PM · iostouchphase

iOS TouchPhase.Began Detected Multiple Times

I have a buggy iOS program I can't figure out. I've boiled it down to a simple problem, the TouchPhase.Began code is being run twice, even though the user is just touching my object with the code once. I created a small program to show the problem. Basically, I have a big sphere that when the user touches, I want it to register as one touch. For some reason, when the sphere is touched, the counter tracking touches usually counts multiple touches. I've spent hours with no luck. Here's the code in full:

 private var hit : RaycastHit;
 private var ray : Ray;
 var inputCamera : Camera;
 private var i:int = 0;
 private var hitTag:String;
 private var touchId:int;
 
 function FixedUpdate (){
     if (Input.touchCount > 0) {
        var touch : Touch = Input.touches[0];
         ray = inputCamera.ScreenPointToRay(touch.position);
            if(Physics.Raycast(ray, hit)){
                hitTag = hit.transform.tag;
               switch (touch.phase) {
                 case TouchPhase.Began:
                     if (hitTag == "orangeBttn") {
                            i++;
                 break;
                   }
             }
         }
       }
 }
     
     
 function OnGUI () {
     GUI.Label (Rect (10, 10, 100, 50), "Orange hit " + i);
 }    


I can send the program if anyone is interested, but basically I just have the code on a sphere, and run it on the iPad (not just the remote). When the user touches the sphere (tagged orangeBttn), variable i should be incremented by 1. Instead, most of the time its incremented by 2. There's work arounds,but can some body tell me why this simple thing isn't working? Thanks in advance.

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
8
Best Answer

Answer by unityRookie · Feb 29, 2012 at 02:41 AM

In case anyone else runs across this problem in the future, the problem was I had the TouchPhase event code in the FixedUpdate function, which made it buggy. I put it in the Update function and it solved the problem.

Comment
Add comment · Show 4 · 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 davvilla · May 08, 2013 at 06:35 PM 0
Share

Thanks! You saved me a lot of hassle with this

avatar image Shifty-Geezer · Mar 18, 2014 at 09:21 AM 0
Share

Thanks. Just run into same problem with old Android TF101 getting double touches. Would vote up but can't as not enough rep yet.

avatar image PaulOllivier · Jun 03, 2017 at 03:22 PM 0
Share

How is this still a bug? I'm using Unity 5.6 ( 2017 ), this answer dates from 2012...

avatar image rtilton1 · Aug 22, 2019 at 12:58 AM 0
Share

Still a bug... doesn't work correct in FixedUpdate. touch.phase events happen multiple times in fixedUpdate...

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

Decting iOS touch input in Fixed Update 1 Answer

How do I change the texture of a gameobject only while a touch is on it on iOS? 1 Answer

Input.touchCount returning wrong number 0 Answers

Touch count & Raycasting on mobile 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 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