Create Animation in unity3d only on one axis

Hi , i try to create animation in unity3D for move game object between -5 and 5 on x axis . i want to when i attach this animation to object its move between -5 and 5 , but my problem is : when i add curve to x axis unity automatically add curve to y and z too ! so when i attach this animation to other object its change object transform position on x y z axis but i only need to move on x ! what should i do for solve this problem ? thanks

You can not create a curve for X only. Unity doesn’t keep 3 curves of float, it keeps one curve of Vector3. That’s why it always comes in triplet (x y z).

You have to workaround your problem in some other way, for example: overriding y and z in LateUpdate (i.e. after animation has been sampled), or sample animation on another object and copy x value from it.