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!

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