Unity: Dial-like Animation Resetting

Viewed 29

(For anyone that understands, this is a simulator for an Omnitrix from Ben10 lol)

Explanation: I am trying to create a dial-like program. When an arrow key is pressed, an animation for a dial rotating plays, but it resets to the default position right after. The animation rotates the dial 20 degrees to the right or left, depending on the key pressed. How do I make the object stay at the 20-degree angle after the animation has played, and have the next animation start at the 20-degree angle and rotate to 40 degrees?

What I tried was to have the animation play and then change the rotation angle of the object to 20 degrees directly after so that it could increase to 40 from there, but that did not work (for reasons I have not figured out).

Code: Ignore the inner if and print statements; those work as intended for debugging other areas of the project. The transform.Rotate statement at the end is the way that I tried to have my idea work, but it was unfunctional.

void Update()
    {
        if (Input.GetKeyDown("d") || Input.GetKeyDown("right"))
        {
            anim.Play("twistRight");
            if (numAliens >= 17)
            {
                numAliens = 0;
            }
            else
            {
                numAliens++;
            }
            print("right" + numAliens);
            twistObject.transform.Rotate(0, 20, 0);
        }
        if (Input.GetKeyDown("a") || Input.GetKeyDown("left"))
        {
            anim.Play("twistLeft");
            if (numAliens <= 0)
            {
                numAliens = 17;
            }
            else
            {
                numAliens--;
            }
            print("left" + numAliens);
            twistObject.transform.Rotate(0, -20, 0);
        }
    }

Animator: I think that the fact that the animations transition into the default state is what is causing this, but I do not know how else to have this program work under my current (unfunctional) structure of code. Without transitioning into the default state, it does not let me play the same animation multiple times consecutively, so I felt that this was the only option.

animator screenshot

Any and all help is greatly appreciated. Thank you in advance!

Link to demonstration: https://drive.google.com/file/d/1I5Z2lQ-R9nWzC2rQ7Z389YGldmQcaeU1/view?usp=sharing

0 Answers
Related