Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created June 27, 2018 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/de59067c22f93e0de78a11d089ffce5d to your computer and use it in GitHub Desktop.
Save todorok1/de59067c22f93e0de78a11d089ffce5d to your computer and use it in GitHub Desktop.
円の範囲内に小さなオブジェクトをランダムにインスタンス化する
[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