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 tmw8407 · Feb 04, 2011 at 04:33 PM · updatefunctionincrementfinite-state-machine

Update increment error (2 + 1 = 0?)

Hi everyone,

I'm trying to create a simple animation to demonstrate the controls for the user when the game is paused. I'm using EZGUI to create two textures that are shifted around depending on the animation.

The animation is divided into stages that are controlled by an integer "movieState." Once one stage is complete, movieState is incremented.

The problem is that the animation is sometimes skipping the last state and returning to the first one. I have no idea how this is happening, as the last state is the only one that should be able restart the animation.


Here's the code:

function AnimateNormalMove() // animation based on "pinch-out" gesture { switch (movieState) { case 0: // initialize variables Debug.Log("===================================="); // fingerOne and fingerTwo are the two textures fingerTwo.gameObject.active = true; fingerOne.gameObject.active = true;

         // set the fingers' key positions
         fingerOneStartPos = Vector3(25, 0, fingerOne.localPosition.z);
         fingerTwoStartPos = Vector3(-25, 0, fingerOne.localPosition.z);
         fingerOneEndPos = Vector3(125, 0);
         fingerOne.localPosition = fingerOneStartPos;
         fingerTwo.localPosition = fingerTwoStartPos;

         // other variables
         moveSpeed = defaultMoveSpeed;
         waitTime = .75; // controls pauses between states

         Debug.Log("moving from state " + movieState);
         movieState ++;
         Debug.Log(" to state " + movieState);
         break;
     case 1: // start with the fingers close together, pause briefly, then move them apart
         if (waitTime > 0) {
             waitTime -= Time.deltaTime;
         } else {
             fingerOne.localPosition.x += moveSpeed * Time.deltaTime;
             fingerTwo.localPosition.x -= moveSpeed * Time.deltaTime;
             // once the fingers have reached far enough, go to the next state
             if (fingerOne.localPosition.x > fingerOneEndPos.x) {
                 waitTime = .3;

                 Debug.Log("moving from state " + movieState);
                 movieState ++;
                 Debug.Log(" to state " + movieState);
             }
         }
         break;
     case 2: // pause briefly, clear the fingers, then go to the next state
         if (waitTime > 0) {
             waitTime -= Time.deltaTime;
         } else {
             fingerOne.gameObject.active = false;
             fingerTwo.gameObject.active = false;
             waitTime = 1.5;

             Debug.Log("moving from state " + movieState);
             movieState ++;
             Debug.Log(" to state " + movieState);
         }
     case 3:  // pause before restarting the animation
         if (waitTime > 0) {
             waitTime -= Time.deltaTime;
         } else {
             Debug.Log("moving from state " + movieState);
             movieState = 0;
             Debug.Log(" to state " + movieState);
         }
         break;
 }

}


Here's a sample output:


alt text


Somehow the movieState is getting set to 0 without ever hitting state 3. I've deleted all other references to movieState except for the initialization, so I know it's not getting reset by another function.

This function seems to work correctly when called from FixedUpdate() rather than Update(), but I'm not sure why. I've also tried setting movieState directly, rather than incrementing it, but it hasn't helped.

Thanks in advance for your help!

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

Answer by DaveA · Feb 04, 2011 at 05:53 PM

I think you need a break; at the end of case 2

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 tmw8407 · Feb 04, 2011 at 06:33 PM 0
Share

That was it. Somehow I knew it was going to be an embarrassingly simple fix.

Thanks for the help!

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

No one has followed this question yet.

Related Questions

Would like a function to change a parameter once, after an "if" statement has been met. 1 Answer

Unity won't start since updating ver 3.3 to 3.4 0 Answers

How to Update a score count going up and down 1 Answer

Unity Touch=2 commends? 1 Answer

Unity Auto-update problem??? 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