How to make fence spawn every 1 unit along the length of the wall?

I am trying to instantiate my fence along the length of the wall. So basically, when I click the mouse button down I drag the wall and then when I lift the mouse button up I want it to spwan that many fences per 1 unit along the length of the wall (however long the wall is, spawn that many fences every 1 unit). Can someone help me in this, I am trying to do it, but I am not successful. What I am trying to create is shown in this video from 0:54

using UnityEngine;
using System.Collections;

public class CreateWalls : MonoBehaviour {
	ShowMousePosition pointer;
	bool creating;
	public GameObject start;
	public GameObject end;

	public GameObject wallPrefab;
	GameObject wall;

	public GameObject polePrefab;
	public GameObject fencePrefab;
	GameObject lastPole;

	bool xSnapping;
	bool zSnapping;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		getInput();
	}

	void getInput() {
		if(Input.GetMouseButtonDown(0)) {
			setStart();
			if (zSnapping.Equals (xSnapping)) {
				zSnapping = true;
			} else {
				zSnapping = false;
			}

			if (xSnapping.Equals (zSnapping)) {
				xSnapping = true;
			} else {
				xSnapping = false;
			}

		} else if(Input.GetMouseButtonUp(0)) {
			setEnd ();
			Destroy (wall);
			//updateFence ();
		} else {
			if(creating) {
				adjust();
				updateFence ();
			}
		}
	}

	void setStart() {
		Vector3 startPos = pointer.getWorldPoint ();
		creating = true;
		start.transform.position = pointer.snapPosition(startPos);
		wall = (GameObject)Instantiate (wallPrefab, start.transform.position, Quaternion.identity);
		startPos = pointer.snapPosition (startPos);
		GameObject startPole = Instantiate (polePrefab, start.transform.position, Quaternion.identity);
		startPole.transform.position = new Vector3 (start.transform.position.x, startPos.y + 0f, start.transform.position.z);
		lastPole = startPole;
	}

	void setEnd() {
		creating = false;
	}

	void updateFence() {
		Vector3 current = pointer.getWorldPoint ();
		current = pointer.snapPosition (current);
		current = new Vector3 (current.x, current.y + 0f, current.z);
		if (!current.Equals (lastPole.transform.position)) {
			createFenceSegment (current);
		}
	}

	void createFenceSegment(Vector3 current) {
		GameObject newPole = Instantiate (polePrefab, current, Quaternion.identity);
		float distance = Vector3.Distance (newPole.transform.position, lastPole.transform.position);
		Vector3 middle = Vector3.Lerp (newPole.transform.position, lastPole.transform.position, 0.5f);
		GameObject newFence = Instantiate (fencePrefab, middle, Quaternion.identity);
		newPole.transform.rotation = newFence.transform.rotation;
		newFence.transform.localScale = new Vector3 (newFence.transform.localScale.x, newFence.transform.localScale.y, distance);
		newFence.transform.LookAt (lastPole.transform);
		lastPole = newPole;
	}

	void adjust() {
		Vector3 startPos = pointer.getWorldPoint ();
		end.transform.position = pointer.snapPosition(startPos);

		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 distanceo = Vector3.Distance(start.transform.position, end.transform.position);
		wall.transform.position = start.transform.position + distanceo/2 * start.transform.forward;
		wall.transform.rotation = start.transform.rotation;
		wall.transform.localScale = new Vector3(wall.transform.localScale.x, wall.transform.localScale.y, distanceo);
	}
}

Hi @PE2 I tried a different solution to the wall building, see if it works for you. Appologies if there are any errors, I can’t test it where I am now:

/* Public Variables */
public GameObject wallPrefab;

/* Private Variables */
Vector3 _start;
Vector3 _end;
Vector3 _dir;
int wallLength;

void FixedUpdate () {
	// On Click
	if (Input.GetKeyDown(KeyCode.Mouse0))
		StartWall ();
	
	// On Drag
	if (Input.GetKey(KeyCode.Mouse0))
		DragWall ();
		
	// On Let Go
	if (Input.GetKeyUp(KeyCode.Mouse0))
		BuildWall ();
}


void StartWall () {
	// Ray
	Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
	
	// hit
	Raycasthit hit;
	
	Physics.Raycast(ray, out hit);
	_start = hit.point;
}

void DragWall () {
	// Ray
	Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
	
	// hit
	Raycasthit hit;
	
	Physics.Raycast(ray, out hit);
	_end = hit.point;
	
	wallLength = Mathf.floor (Vector3.Distance(start, end));
}

void BuildWall () {
	// Get build direction
	_dir = (end - start).normalized;
	
	// Build the wall
	for (int i = 0; i < wallLength; i++) {
		// build position
		Vector3 pos = _dir * i;
		
		// Snap the build position
		Vector3 pos = new Vector3(Mathf.Round(pos.x), pos.y, Mathf.Round(pos.z));
		
		// Place the wall
		Instantiate (wallPrefab, pos);
	}
}