private GameObject CreatePlanet(PlanetType type, int planetIndex) { GameObject newPlanet = Instantiate(planetPrefab); newPlanet.transform.SetParent(planetParent.transform); PlanetInitializationValues startValues = new PlanetInitializationValues(); startValues.image = GenerateRandomSprite(); startValues.scale = UnityEngine.Random.Range(sizeRange[0], sizeRange[1]); startValues.speed = UnityEngine.Random.Range(planetRotationSpeedsRange[0], planetRotationSpeedsRange[1]); startValues.sunPosition = sun.transform.position; startValues.distanceToSun = new Vector2(sun.transform.position.x + distanceToSun + distanceBetweeenPlanets * planetIndex, sun.transform.position.y); startValues.maxHP = UnityEngine.Random.Range(maxPlanetHPRange[0], maxPlanetHPRange[1]); startValues.planetType = type; if (type == PlanetType.Player) { newPlanet.AddComponent <PlayerPlanetAttack>(); } else { newPlanet.AddComponent <EnemyPlanetAttack>(); } var randomRocket = rocketManager.GetRandomRocket(); startValues.rocketType = randomRocket.GetRocketType(); startValues.reloadingTime = randomRocket.GetCooldown(); PlanetController planetController = newPlanet.GetComponent <PlanetController>(); planetController.Initialize(startValues); return(newPlanet); }