Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created June 27, 2018 09:29
Show Gist options
  • Save todorok1/90c9847b2387cacb30dff76f512a6e1e to your computer and use it in GitHub Desktop.
Save todorok1/90c9847b2387cacb30dff76f512a6e1e to your computer and use it in GitHub Desktop.
球体内に小さなオブジェクトをランダムにインスタンス化する
void InstantiateSmallCubeInSphere(){
for (int i = 1; i <= batchNum; i++){
Vector3 position = Random.insideUnitSphere;
position.x *= cubeSize.x / 2f;
position.y *= cubeSize.y / 2f;
position.z *= cubeSize.z / 2f;
position += offset;
// Prefabをインスタンス化する
GameObject obj = Instantiate(cubePrefab, 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