private void CreateNewPlanets() { planetsCount = Random.Range(Settings.i.minOpponentsCount, Settings.i.maxOpponentsCount) + 1; for (var i = 1; i <= planetsCount; i++) { float planetSize = Random.Range(Constants.k_MinPlanetSize, Constants.k_MaxPlanetSize); Color planetColor = GetUniqueRandomColorForAPlanet(); GameObject planet = sphereGenerator.CreatePlanet(planetColor, planetSize); planet.name = "Planet " + i.ToString(); Planet planetComp = planet.AddComponent <Planet>(); float density = Constants.k_MaxPlanetDensity; float orbitSpeed = Random.Range(Constants.k_MinPlanetOrbitSpeed, Constants.k_MaxPlanetOrbitSpeed); planetComp.Configure(planet.name, planetColor, planetSize, density, orbitSpeed); planet.transform.position = new Vector3(14 * i, 0, 0); //set orbit planet.transform.RotateAround(Vector3.zero, Vector3.forward, Random.Range(0, 360)); //place on random point on the orbit ArtileryCommander commander = planet.GetComponent <ArtileryCommander>(); uiProgressBar.SubscribeOnArtileryCommander(commander); Damageable damageable = planet.GetComponent <Damageable>(); float planetHealth = planetSize * planetComp.mass; damageable.SetHealth(planetHealth, planetHealth); uiHealthBar.SubscribeOnDamageable(damageable); planets.Add(planet); } }
private void LoadGameState() { GameState state = SaveManager.i.gameData.state; this.score = state.score; this.kills = state.kills; this.playerName = state.playerName; this.playerWeaponName = state.playerWeaponName; this.planetsCount = state.numberOfPlanets; foreach (var savedPlanet in state.planets) { Color planetColor = new Color { r = savedPlanet.colorR, g = savedPlanet.colorG, b = savedPlanet.colorB }; GameObject planet = sphereGenerator.CreatePlanet(planetColor, savedPlanet.size); planet.name = savedPlanet.name; Planet planetComp = planet.AddComponent <Planet>(); planetComp.Configure(planet.name, planetColor, savedPlanet.size, savedPlanet.density, savedPlanet.orbitSpeed, savedPlanet.mass); planet.transform.position = new Vector3(savedPlanet.pos[0], savedPlanet.pos[1], savedPlanet.pos[2]); ArtileryCommander commander = planet.GetComponent <ArtileryCommander>(); commander.SetWeapon(savedPlanet.weaponName); uiProgressBar.SubscribeOnArtileryCommander(commander); Damageable damageable = planet.GetComponent <Damageable>(); float maxHealth = savedPlanet.size * savedPlanet.mass; damageable.SetHealth(maxHealth, savedPlanet.health); if (savedPlanet.health == 0) { damageable.isDead = true; planet.SetActive(false); } uiHealthBar.SubscribeOnDamageable(damageable); planets.Add(planet); } List <UIPointerTarget> pointerTargets = new List <UIPointerTarget>(); for (int index = 0; index < planets.Count; index++) { var planet = planets[index]; if (planet.name == playerName) { playerPlanetIndex = index; planet.AddComponent <PlayerPlanet>(); cameraController.SetTarget(planet.transform, false); planet.AddComponent <ShieldCommander>(); uIPointer.SetPlayer(planet.transform); } else { planet.AddComponent <AIPlanet>(); pointerTargets.Add(new UIPointerTarget(planet.transform, GameAssets.i.pointerSprite)); } } uIPointer.SetTargets(pointerTargets); UpdateHUD(); }