46 lines
859 B
C#
46 lines
859 B
C#
using UnityEngine;
|
|
|
|
public class FishSpawnTest : MonoBehaviour
|
|
{
|
|
public GameObject fishPrefab;
|
|
|
|
public int fishCount;
|
|
|
|
public Vector3 area;
|
|
|
|
private void Start()
|
|
{
|
|
SpawnEntities(fishPrefab, fishCount, 1f, area);
|
|
}
|
|
|
|
private void SpawnEntities(GameObject prefab, int count, float spacing, Vector3 startPosition)
|
|
{
|
|
int num = Mathf.CeilToInt(Mathf.Pow(count, 1f / 3f));
|
|
int num2 = 0;
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
if (num2 >= count)
|
|
{
|
|
break;
|
|
}
|
|
for (int j = 0; j < num; j++)
|
|
{
|
|
if (num2 >= count)
|
|
{
|
|
break;
|
|
}
|
|
for (int k = 0; k < num; k++)
|
|
{
|
|
if (num2 >= count)
|
|
{
|
|
break;
|
|
}
|
|
Vector3 position = startPosition + new Vector3((float)i * spacing, (float)j * spacing, (float)k * spacing);
|
|
Object.Instantiate(prefab, position, Quaternion.identity);
|
|
num2++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|