How it works...

You created a C# script class, ChangePitch, and added an instance to the animatedRocket GameObject. It declares several variables, the most important of which is acceleration.

It's Awake() method caches references to the Animator and AudioSource sibling components. The Start() method sets the initial speed from the Animator, and calls the AccelerateRocket(...) method, passing 0 to calculate the resulting pitch for the Audio Source.

In each frame, the Update() method tests for keyboard keys 1 and 2. When detected, they call the AccelerateRocket(...) method, passing a positive or negative value of acceleration as appropriate.

The AccelerateRocket(...) method increments variable speed with the received argument. The Mathf.Clamp() command limits the new speed value between the minimum and maximum speed. Then, it changes the Animator speed and Audio Source pitch according to the new speed absolute (positive) value. The value is then clamped a second time to avoid negative numbers. If you wish to reverse the animation, check out the code files in the solution provided for this recipe.

Please note that setting the animation speed, and therefore the sound pitch, to 0 will cause the sound to stop, making it clear that stopping the object's animation also prevents the engine sound from playing.