void Start() { if (asteroidArrayPrefab) { SpawnAsteroidConfig spawnAsteroidConfig = new SpawnAsteroidConfig(); List <GameObject> asteroidsList = new List <GameObject>(); foreach (Transform child in asteroidArrayPrefab.transform) { child.gameObject.GetComponent <AsteroidController>().spawnZone = spawnZone.GetComponent <Collider2D>(); child.gameObject.GetComponent <AsteroidController>().gameController = this; asteroidsList.Add(child.gameObject); } spawnAsteroidConfig.SetAsteroidToSpawn(asteroidsList); spawnAsteroidConfig.SetMaxAsteroidsToSpawn(10); StartCoroutine("CreateAsteroids", spawnAsteroidConfig); } Camera cam = GetComponentInParent <Camera>(); float aspect = (float)Screen.width / Screen.height; float orthoSize = cam.orthographicSize; float width = 2.0f * orthoSize * aspect; float height = 2.0f * cam.orthographicSize; GetComponent <BoxCollider2D>().size = new Vector2(width, height); }
private IEnumerator CreateAsteroids(SpawnAsteroidConfig spawnAsteroidConfig) { for (int i = 0; i < spawnAsteroidConfig.GetMaxAsteroidsToSpawn(); i++) { yield return(new WaitForSeconds(spawnAsteroidConfig.GetSeconds())); this.CreateAsteroid(spawnAsteroidConfig); } }
private void CreateAsteroid(SpawnAsteroidConfig spawnAsteroidConfig) { GameObject newAsteroid = Instantiate(spawnAsteroidConfig.GetAsteroidToSpawn(), new Vector2(-20f, 0f), Quaternion.identity); newAsteroid.transform.SetParent(asteroidGroup.transform); }