将脚本erweishuzu挂在Main Camera上
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class erweishuzu : MonoBehaviour {
void Start () {
int temp = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 5; j++)
{
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
go.name = (temp).ToString();
temp++;
go.transform.position = new Vector3(i * 2, -j * 2, 0);
}
}
}
void Update () {
}
}
循环要写在start里,只执行一次就行了。