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;
}
}