[Newby] Need help with navigating between a previous and next position

I want to setup a Mario like map system (see 1)

Currently I use this code to see where the player can go.

nextButton = currentButton.GetComponent<LevelButton> ().next;
		previousButton = currentButton.GetComponent<LevelButton> ().next;

		if (nextButton.transform.position.x > this.transform.position.x) {
		canMoveRight = true;
	} else if (nextButton.transform.position.x < this.transform.position.x) {
		canMoveLeft = true;
	} else if (nextButton.transform.position.y > this.transform.position.y) {
		canMoveUp = true;
	} else if (nextButton.transform.position.y < this.transform.position.y) {
		canMoveDown = true;
	} 

		if (previousButton.transform.position.x > this.transform.position.x) {
			canMoveRight = true;
		} else if (previousButton.transform.position.x < this.transform.position.x) {
			canMoveLeft = true;
		} else if (previousButton.transform.position.y > this.transform.position.y) {
			canMoveUp = true;
		} else if (previousButton.transform.position.y < this.transform.position.y) {
			canMoveDown = true;
		}

Any noob can see that using this only one direction will be set to true. Also, the booleans will stay on true.

How can I fix this? Or perhaps even optimize this code?

Any help is appreciated!

That’s what the booleans are for, here’s the complete script:

using UnityEngine;
using System.Collections;

public class LevelSelectController : MonoBehaviour {

	public bool canMoveLeft;
	public bool canMoveRight;
	public bool canMoveUp;
	public bool canMoveDown;

	public bool canMove;

	public GameObject previousButton;
	public GameObject nextButton;

	public GameObject currentButton;

	public float speed = 5.0f;

	// Use this for initialization
	void Start () {
		this.transform.position = GameObject.Find ("LevelButton").transform.position;
		currentButton = GameObject.Find ("LevelButton");

		canMove = true;
	}
	
	// Update is called once per frame
	void Update () {
		nextButton = currentButton.GetComponent<LevelButton> ().next;
		previousButton = currentButton.GetComponent<LevelButton> ().next;

		if (nextButton.transform.position.x > this.transform.position.x) {
			canMoveRight = true;
		} else if (nextButton.transform.position.x < this.transform.position.x) {
			canMoveLeft = true;
		} else if (nextButton.transform.position.y > this.transform.position.y) {
			canMoveUp = true;
		} else if (nextButton.transform.position.y < this.transform.position.y) {
			canMoveDown = true;
		} 

		if (previousButton.transform.position.x > this.transform.position.x) {
			canMoveRight = true;
		} else if (previousButton.transform.position.x < this.transform.position.x) {
			canMoveLeft = true;
		} else if (previousButton.transform.position.y > this.transform.position.y) {
			canMoveUp = true;
		} else if (previousButton.transform.position.y < this.transform.position.y) {
			canMoveDown = true;
		}

		if (Input.GetKeyDown (KeyCode.A) && canMoveLeft && canMove) {
			StartCoroutine(Move());
		}

		if (Input.GetKeyDown (KeyCode.D) && canMoveRight && canMove) {
			StartCoroutine(Move());
		}

		if (Input.GetKeyDown (KeyCode.W) && canMoveUp && canMove) {
			StartCoroutine(Move());
		}

		if (Input.GetKeyDown (KeyCode.S) && canMoveDown && canMove) {
			StartCoroutine(Move());
		}

		if (Input.GetKeyDown (KeyCode.E)) {
			Application.LoadLevel(currentButton.GetComponent<LevelButton>().level);
		}
	}

	IEnumerator Move(){
		canMove = false;

		GameObject next = currentButton.GetComponent<LevelButton> ().next;
		GameObject prev = currentButton.GetComponent<LevelButton> ().prev;

		if (currentButton.GetComponent<LevelButton> ().next == nextButton) {
			this.transform.position = next.transform.position;
//			transform.position = Vector3.MoveTowards(transform.position, next.transform.position, speed * Time.deltaTime);
			currentButton = next;

			if(transform.position == next.transform.position){
				canMove = true;
			}
		} else if (currentButton.GetComponent<LevelButton> ().prev == previousButton) {
			this.transform.position = prev.transform.position;
//			transform.position = Vector3.MoveTowards(transform.position, prev.transform.position, speed * Time.deltaTime);
			currentButton = prev;

			if(transform.position == prev.transform.position){
				canMove = true;
			}
		}

		yield break;
	}
}

Do note it’s not fully done yet, this is about 15-20 minutes of work.

The currentButton is a object the player is on, like the level squares on the Mario map.