Instantiate a four cornered wall!

I thought it would be nice to line my terrain will a simple perimeter wall, but I feel like there is a more elegant way of doing so. The code below (C#) works well, just drag and drop a square “wall” prefab into the editor. Ah, what else? This is my first post here on the Unity forums, and I figured this could be a good conversation starter.

public GameObject wall;
Vector3 v3;
	
	// Use this for initialization
	void Start (){
	
		for (int i = 0; i < 100; i++) // My terrain is 4 * 100
		{
			v3 = transform.position + Vector3.right * i;
			GameObject go = Instantiate(wall,v3,Quaternion.identity)as GameObject;
			go.transform.parent = this.transform;
		}
		
		for (int i = 0; i < 100; i++)
		{
			v3 = transform.position + Vector3.forward * i;
			GameObject go = Instantiate(wall,v3,Quaternion.identity)as GameObject;
			go.transform.parent = this.transform; // Use this to manage clutter in the editor 
		}
		
		for (int i = 0; i < 100; i++)
		{
			Vector3 v3Adj = new Vector3(99,0,99); // minus one to cover the gap
			v3 = v3Adj + Vector3.back * i;
			GameObject go = Instantiate(wall,v3,Quaternion.identity)as GameObject;
			go.transform.parent = this.transform;
		}
		
		for (int i = 0; i < 100; i++)
		{
			Vector3 v3Adj = new Vector3(99,0,99);
			v3 = v3Adj + Vector3.left * i;
			GameObject go = Instantiate(wall,v3,Quaternion.identity)as GameObject;
			go.transform.parent = this.transform;
		}
	
	}

Seems you have 400 objects when 4 would do?

–Eric

I guess four would work, but the standard cubes look pretty stretched out when I apply a texture.

That’s why you’d adjust the tiling in the material.

–Eric

Ah, I have never touched the tiling of the material but it makes sense now that I think about it. I also suppose using four walls over four-hundred smaller pieces is a good thing too. I will still keep the code for making forts or little bunkers, that might be a better application.