Updating Array of Prefabs

I am trying to create a straight line filled with prefabs which update their position as the mouse is dragged. For visualisation purposes I have three prefabs, one set at the mouse position when it is clicked, the second at the point where the current mouse position is and the third in the middle. In the inspector I can see that the array is being created and filled with the prefabs, it grows and shrinks depending on the distance between start and end positions. However it is not being instantiated, and even if it was, I am not sure of how to change each position in the array so the objects align correctly. Could somebody point me in the right direction please. The basic idea being to draw a line, like in a basic drawing package, only made from prefabs instead of pixels.

Thank you.

using UnityEngine;
using System.Collections;

public class instance : MonoBehaviour {

public GameObject myPrefab;
public Vector3 startPoint;
public Vector3 endPoint;
public float mouseDistance;
public bool trackMouse = false;
private GameObject endBlock;
private GameObject midBlock;
private GameObject startBlock;
public GameObject[] midArray;
public int segments;

void OnGUI () {

GUI.Label (new Rect (25, 25, 100, 30), "Length:" + ((int)mouseDistance).ToString()); 
GUI.Label (new Rect (25, 60, 100, 30), "Segments:" + segments.ToString()); 

segments = (int)mouseDistance/10;

midArray = new GameObject[segments];
for (int i = 0; i < segments; i++)
        {
        	midArray *= midBlock;*

}
}

void Update () {

  • Vector3 startPos = Camera.main.ScreenToWorldPoint(startPoint);*
    
  • Vector3 endPos = Camera.main.ScreenToWorldPoint(endPoint);*
    

if (Input.GetMouseButtonDown(0)) {

  •  startBlock = (GameObject) Instantiate(myPrefab, startPos, Quaternion.identity);*
    
  •  midBlock = (GameObject) Instantiate(myPrefab, startPos, Quaternion.identity);*
    
  •  endBlock = (GameObject) Instantiate(myPrefab, endPos, Quaternion.identity);*
    

startPoint = Input.mousePosition;
startPoint.z = 1.0f;
trackMouse = true;
}

if (Input.GetMouseButtonUp(0)) {
trackMouse = false;
mouseDistance = 0;

  •  }*
    
  • if (trackMouse){*

  • mouseDistance = (endPoint - startPoint).magnitude;*

  • startBlock.transform.position = startPos;*

  • midBlock.transform.position = (endPos-startPos)/2.0f + startPos;*

  • endBlock.transform.position = endPos;*
    endPoint = Input.mousePosition;
    endPoint.z = 1.0f;

  • }*

  • }*
    }

hey mate,

is your camera prespective or ortho?

i just tested you script in an ortho cam and it works great.

edit:
what segments are you talking you are just adding to the array the same midpart prefab.

so you have an an array of 60 prefabss that are the same gameobject (midblock).

sfc.