I'm a programming noob, which of these two coding styles is best?

First, don’t repeat yourself. If you find yourself writing something complicated like spinAnim["spin"] twenty seven thousand times, do yourself a favor and assign it to a temporary variable at the start of everything.

Second, never compare floating point values for equality, such as line 34 in the second script, and even (more subtly) the line 15 Mathf.Abs() > 0 comparision, which is effectively just asking if it is not equal to zero. Never compare for equality, but rather ask if it is close enough, either by difference or by using Mathf.Approximately().

Finally, I’m not sure what you’re even doing there, but if all you are doing is moving one value smoothly towards another, you can do that with a LOT fewer moving parts, then send the value out to your animator all at once:

Smoothing movement between any two particular values:

You have currentQuantity and desiredQuantity.

  • only set desiredQuantity
  • the code always moves currentQuantity towards desiredQuantity
  • read currentQuantity for the smoothed value

Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.

The code: SmoothMovement.cs · GitHub

Finally, as with ANY performance question, staring at code is useless. It’s simply NOT a thing.

DO NOT OPTIMIZE CODE RANDOMLY… always start by using the profiler:

Window → Analysis → Profiler

Optimizing UnityEngine.UI setups: