Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
円の範囲内に小さなオブジェクトをランダムにインスタンス化する
[SerializeField]
List<GameObject> prefabs;
void InstantiateCubesInCircle(){
for (int i = 1; i <= batchNum; i++){
Vector2 position = Random.insideUnitCircle;
position.x = position.x * cubeSize.x / 2f + offset.x;
position.y = position.y * cubeSize.y / 2f + offset.y;
// Prefabをインスタンス化する
GameObject prefab = prefabs[Random.Range(0, prefabs.Count - 1)];
GameObject obj = Instantiate(prefab, position, Quaternion.identity);
obj.transform.SetParent(gameObject.transform);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.