generate instances at specific positions in JavaScript

var myBox: Transform;

function Start () {

for (i = 0; i<10; i++) {

    for (j =0; j<10; j++) {
         var xpos = i * 10;       
         var zpos = j * 10 ; 
         var instanceObj = Instantiate (myBox, Vector3(xpos, 0, zpos), Quaternion.identity);
   }
}

}

I’m a real beginner and i cant program for the life of me, what im trying to do is manipulate the script i have now to produce my generated boxes into a triangular pattern. any help out there for a total newb?

You could do this all sorts of ways. Pattern generation is simply an image, so you could draw an image and query for pixels in the image. If you're going to be doing all sorts of shapes, I'd use a generic system that could take drag and drop textures.

You could do programmer art with an array...


var positions =
[
    [1,0,0,0,0,0,0,0,0,0],
    [1,1,0,0,0,0,0,0,0,0],
    [1,0,1,0,0,0,0,0,0,0],
    [1,0,0,1,0,0,0,0,0,0],
    [1,0,0,0,1,0,0,0,0,0],
    [1,0,0,0,0,1,0,0,0,0],
    [1,0,0,0,0,0,1,0,0,0],
    [1,0,0,0,0,0,0,1,0,0],
    [1,0,0,0,0,0,0,0,1,0],
    [1,1,1,1,1,1,1,1,1,1]
];

for (i = 0; i < 10; i++)
{
    for (j = 0; j < 10; j++)
    {
         var xpos = i * 10;       
         var zpos = j * 10;

         if(positions*[j] > 0)*
 *{*
 *var instanceObj = Instantiate(myBox, Vector3(xpos, 0, zpos), Quaternion.identity);*
 *}*
 *}*
*}*
*```*
*<p>Loop through the array and check if an integer is not zero.  You could expand that to use different integers for different object types.  Of course, you could do that with an image and the rgba values. :)</p>*

That works too :

public class GenerateTriangle : MonoBehaviour 
{
	public Vector3 a, b, c;
	public float col, line;
	public GameObject prefab;
	
	void Start()
	{
		for( int i = 0; i < line; i++ )
			for( int j = 0; j < col; j++ )
				Instantiate( prefab, Vector3.Lerp( Vector3.Lerp( a, b, j / (col-1) ), c, i / (line-1) ), Quaternion.identity );
	}
	
	void OnDrawGizmosSelected()
	{
		Gizmos.color = Color.red;
		Gizmos.DrawSphere( a, 0.5F );
		Gizmos.color = Color.green;
		Gizmos.DrawSphere( b, 0.5F );
		Gizmos.color = Color.blue;
		Gizmos.DrawSphere( c, 0.5F );
	}
}