Oh, so you mean that they only move forward/backward on a line, and not sideways?
Hm, for player controls it's probably best to use a custom control for that - alternatively, you could use the Button control and use a None input key for the movement axis you don't want to use.
For enemy movement, if you're using the move AI - either use NavMesh agents and have the navmesh limited to a line, or use a custom movement component that limits movement to the line.