Looping and closing walls

Hi I’m trying to elaborate this building wall script;

  1. i want setEnd() to place the “end” of the wall at setStart()'s position.
  2. i also want to make setMiddle() loop.

so when i left click it makes “start” object.
when i left click everytime after it makes “middle” object.
unitl, when i right click it makes “end” object set back to “start”.

void getInput() {
		if (Input.GetMouseButtonDown (0)) {
			setStart ();
		} else if (Input.GetMouseButtonDown(1)) {
			setEnd ();
		} else {
			if (creating) {
				adjust ();
			}
		}

	void setStart() {
		creating = true;
		//start.transform.position = gridSnap(getWorldPoint());
		start.transform.position = getWorldPoint();
		wall = (GameObject)Instantiate(wallPrefab, start.transform.position, Quaternion.identity);
		start = (GameObject)Instantiate (start, start.transform.position, Quaternion.identity);
		setmiddle ();
	}

	void setmiddle() {
		creating = true;
		//start.transform.position = gridSnap(getWorldPoint());
		middle.transform.position = getWorldPoint ();
		wall = (GameObject)Instantiate (wallPrefab, start.transform.position, Quaternion.identity);
		middle = (GameObject)Instantiate (middle, start.transform.position, Quaternion.identity);
		if (Input.GetMouseButtonDown (0)) {
		}
	}
		
	void setEnd() {
		creating = false;
		//end.transform.position = gridSnap(getWorldPoint());
		end.transform.position = getWorldPoint();
		end = (GameObject)Instantiate (end, end.transform.position, Quaternion.identity);
	}

	void adjust() {
		//end.transform.position = gridSnap(getWorldPoint());
		end.transform.position = getWorldPoint();
		if(xSnapping) {
			end.transform.position = new Vector3(start.transform.position.x, end.transform.position.y, end.transform.position.z);
		}
		if(zSnapping) {
			end.transform.position = new Vector3(end.transform.position.x, end.transform.position.y, start.transform.position.z);
		}
		adjustWall();

	}

	void adjustWall() {
		start.transform.LookAt(end.transform.position);
		end.transform.LookAt(start.transform.position);
		float distance = Vector3.Distance(start.transform.position, end.transform.position);
		wall.transform.position = start.transform.position + distance/2 * start.transform.forward;
		wall.transform.rotation = start.transform.rotation;
		wall.transform.localScale = new Vector3(wall.transform.localScale.x, wall.transform.localScale.y, distance);
	}

	Vector3 getWorldPoint() {
		Ray ray = GetComponent<Camera>().ScreenPointToRay (Input.mousePosition);
		RaycastHit hit;
		if(Physics.Raycast(ray, out hit)) {
			return hit.point;
		}
		return Vector3.zero;
	}
}

Thanks for any help in advance…

If I undrestand exactly what you ask, I think that the problem is at the beginning. Try this :

if (Input.GetMouseButtonDown (0) && creating) { adjust(); }
else if (Input.GetMouseButtonDown (0)) { setStart(); }
else if (Input.GetMouseButtonDown(1)) { setEnd(); }