円の範囲内に小さなオブジェクトをランダムにインスタンス化する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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