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 BTStone · May 04, 2012 at 09:31 PM · iphonetouchiphonetouchiphoneinput

Touches don't respond correct

Hey Guys,

so I'm trying to work with Unity iPhone, i got Unity-Remote so i could test the gameplay on my device. Here is my Project-Overview:

  • Plattforming/ SideScrolling Game

  • working with ex2D (Spritemanager-PlugIn, works great so far!)

  • I have a character with no scripts attached (okay, that ex2D script...)

  • That character has also one ex2D-Animation (it's a Move-Animation, Wrapmode is selected as "LOOP")

  • I made two Buttons (made them in Illustrator, exported them as transparent .png files), and using them as GUITexture-Files on the screen itself

So, the Problem is:

i made two scripts for each button with nearly 1:1 code. The Left-Button should move my Playersprite to the left, the Right-Button should move my Playersprite to the right. This is working. My idea is, AFTER i press one of the buttons, the Character starts to move AND the animation is played. I'm trying to work with the Touch-Phases, but i don't get a solution i am satisfied with, because sometimes, my device doesn't recognize a certain phase. When i press the button it's moving all along, that's fine (although, the animation is stuck in the first frame and plays the whole animation after releasing my finger from the screen <- how can i solve this "Sideproblem"). When i release my finger, it sometimes doesn't recognize the Touch-Phase has ended. I made some Debug.Logs to figure out when something happens. I am sitting three days for now in front of this problem, looked up the internet, tried some other "solutions" in order to get nice touch-handling but nothing worked properly, it's devastating, so i beg you, could someone please help?

Of course here is my code so far:

 //public
 public float speed = 10.0f;
 
 //private
 int touchCount = 0;
     playingAnim = false;

 // Objects
 GameObject player; 
 

 void Start () {
     player = GameObject.Find("Ritter");
 
 }
 
 // Update is called once per frame
 void FixedUpdate () {
     
     moving();        
 }
 void moving()
 {
     
     foreach(Touch touch in Input.touches)
     {
         
         if(guiTexture.HitTest(touch.position))
         {
             Debug.Log("PRESSED");
             
             if(touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Stationary)
             {
                 player.transform.Translate(speed*Time.fixedDeltaTime, 0,0);
                 player.GetComponent<exSpriteAnimation>().Play("RitterMove", 0);
         
                 playingAnim = true;
                 
                 Debug.Log("PHASE BEGAN - RIGHT");

             }
             else if(touch.phase == TouchPhase.Stationary)
             {
                 player.transform.Translate(speed*Time.fixedDeltaTime, 0,0);
             player.GetComponent<exSpriteAnimation>().Play("RitterMove");

                 player.transform.Translate(speed*Time.fixedDeltaTime, 0,0);
                 
                 playingAnim = true;

                 
                 Debug.Log("PHASE STATIONARY - RIGHT");

             }
             
             else if(touch.phase == TouchPhase.Ended)
             {
                 playingAnim = false;
                 
                 if(playingAnim == false)
                 {
                     player.GetComponent<exSpriteAnimation>().IsPlaying("RitterMove");
                     player.GetComponent<exSpriteAnimation>().Stop();

                 }
                 
                 Debug.Log("ENDE DES BETATSCHENS! - RIGHT");
             }
         }
     }
             
 
 }
Comment
Add comment · Show 2
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 Steveosaurous · Jun 19, 2012 at 08:04 PM 0
Share

Did you ever get a satisfactory solution to this issue? I've been having a very similar problem for a while now and it is killing my project.

avatar image whydoidoit · Jun 19, 2012 at 09:05 PM 0
Share

Well I can tell you that I had to write my own wrapper that sorted out whether a touch phase had ended or begun because I couldn't get the right values. A missing touch fires a cancelled event for me etc.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by awaxnova · Jun 19, 2012 at 10:12 PM

It looks like playingAnim = false; Should be positioned after the condition that checks if it is false.

if(playingAnim == false) { ... }

playingAnim = false;

That should allow you to stop the animation... the side problem.


For the main issue, could it be that your code is misinterpreting the canceled phase as a begin phase?

http://unity3d.com/support/documentation/ScriptReference/TouchPhase.html

You might be able to confirm if you explicitly handle each touch phase possibility, there are 5, and print a debug log statement for each distinct phase.

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 kreso · Sep 28, 2014 at 06:16 AM

This is a late answer I know, but I had same problem as well. I hope this helps someone else. The solution was to move the code from FixedUpdate() to Update() - that way ended phase was recognized correctly every time.

Comment
Add comment · Show 1 · 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 jamiahuswalton · Apr 06, 2016 at 12:20 AM 0
Share

Thanks @kreso, this solution worked for me. It seems to work now.

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

All objects response to one touch 1 Answer

Unity iPhone scene transition on Tap of GUIText 1 Answer

The iPhoneInput.touchCount is 5 while more or no touch actually. 1 Answer

I want to destroy the top object from a stack of objects on touch, not all objects. 1 Answer

Multitouch problem in Unity iPhone 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