1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
| public class WorldGenerator : MonoBehaviour { CalcCoordinates calculator; GameObject planet; public GameObject[] planetPrefabs; public GameObject[] skyPrefabs; public GameObject[] spacePrefabs; void Start() { calculator = GameObject.FindGameObjectWithTag("Calculator").GetComponent<CalcCoordinates>(); planet = GameObject.FindGameObjectWithTag("Planet");
SpawnObjects(planet, planetPrefabs, PlayerPrefs.GetInt("planetObjectsCount"), 50); SpawnObjects(planet, skyPrefabs, PlayerPrefs.GetInt("skyObjectsCount"), 150); SpawnObjects(planet, spacePrefabs, PlayerPrefs.GetInt("spaceObjectsCount"), 200); }
private void SpawnObjects(GameObject planet, GameObject[] prefabs, float objectCount, float distanceToPlanet) { List<gameObject> spawnObjectsList = new List<gameObject>(); for (int i = 0; i < objectCount; i++) { gameObject spawnObject = prefabs[Random.Range(0, prefabs.Length)]; Vector3 spawnPos = calculator.CalcPointOnSphere(distanceToPlanet); if(CheckSpawnPoint(spawnObjectsList, spawnObject, spawnPos)) { gameObject objectToSpawn = (gameObject)Instantiate(spawnObject, spawnPos, Quaternion.identity); spawnObjectsList.Add(objectToSpawn); } } }
private bool CheckSpawnPoint(List<gameObject> spawnObjectsList, GameObject objectToSpawn, Vector3 spawnPos) { foreach(gameObject listObject in spawnObjectsList) { if(..) { return false; } } return true; } } |