How can I optimise this code?

One, use code tags:

  1. use the input manager and set up axes for these keys. Let it take care of things. And then use Input.GetAxis to get Vector2’s you can then use.