using System.Collections; using System.Collections.Generic; using UnityEngine; public class Generator : MonoBehaviour { public int count = 5; public GameObject source; // Start is called before the first frame update void Start() { Generate(count); } // Update is called once per frame void Update() { } public void Generate(int num) { Vector3 center = transform.position; Vector3 size = transform.lossyScale; Vector3 min = center - 0.5f * size; Vector3 max = center + 0.5f * size; for (int i = 0; i < num; i++) { GameObject b = Instantiate(source); b.name = source.name + (i + 1).ToString("00"); b.transform.position = new Vector3(Random.Range(min.x, max.x), Random.Range(min.y, max.y), Random.Range(min.z, max.z)); } } private void OnDrawGizmosSelected() { Gizmos.color = Color.yellow; Gizmos.DrawWireCube(transform.position, transform.lossyScale); } }