How do i instantiate along the z axis?

So my empty object that i have creates 10 wall segments 10 units apart… How do i make the created segments follow the z axis with the same rotation as the creator so that any rotation i put on to the creator, the wall segments will always follow the z axis in a straight line?

Basically if i rotate the creator and press a button, 10 wall segments will be created 10 units apart in a straight line any way i rotate the creator along the local z axis?

This is what i have so far, but i cant seem to make i follow the z axis in a local straight line… Ive tried a crazy amount of things and been stuck for awhile. Thanks for the help!

#pragma strict
//point B Marker
var target: Transform;
public var Wall: Transform;

var create = false;

function Start () {

}

function Update () {

if(Input.GetKeyUp("space")){

create = true;

}

transform.LookAt(target);

var relativePos = target.position - transform.position;
var Distance = Vector3.Distance(target.position, transform.position);
var ModelsNeeded = Distance / 10;
var Fwd = transform.TransformDirection(Vector3.forward);

print("Distance to other: " + Distance);

print("Models Needed for Distance: " + ModelsNeeded);


if(create == true){

for (var i : int = 0;i < ModelsNeeded; i++) {

Instantiate (Wall, Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z  + (i * 10)), Quaternion.LookRotation(relativePos));
 
create = false;
 
}
}
}

I’m assuming you want the local ‘z’ of the object, not the world ‘z’ axis. It will always be transform.forward. To calculate the position you want:

var v3Pos = transform.position + transform.forward * (i * 10);
Instantiate (Wall, v3Pos, transform.rotation);

I didnt understand your question completely but I guess the following should help you.

lets say you have a prefab named Cube and a clone of that cube is placed in the scene which will be your creator to which you can apply rotation(using some script of yours) and then press some key to create N clones behind it.

public GameObject prefab;

void Start () {

}

void Update () {
	if(Input.GetKey("SomeKey"))
	{
		for(int i=0;i<N;i++)
		{
			Instantiate(prefab,new Vector3(transform.position.x,transform.position.y,transform.position.z + (i*10)),transform.rotation);	
		}
	}		
}

bump! :)…