まずcubeをヒエラルキーに出しassetsの中にドラッグアンドドロップしてプレハブ化したら以下のコードを書きます。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Boxs : MonoBehaviour
{
public GameObject Box;
Vector3 BoxPos;
void Start()
{
for (float x = 0.0f; x < 50.0f; x += 2.0f)
{
for (float y = 0.0f; y < 50.0f; y += 2.0f)
{
for (float z = 0.0f; z < 50.0f; z += 2.0f)
{
BoxPos = new Vector3(x, y, z);
Instantiate(Box, BoxPos, Quaternion.identity);
}
}
}
}
}
ヒエラルキーに空のオブジェクトを出してBoxs.csをアタッチして、プレハブ化したcubeをボックスにドラッグアンドドロップしましょう。
あとは実行ボタンを押してcubeが沢山出ていることを確認しましょう。