using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SolarSystemManager : MonoBehaviour { public GameObject[] objectsToDeactivate; public GameObject[] objectsToActivate; public GameObject[] Planets; public int Industry; public int Wealth; public int Science; public int Food; public int MilitaryPower; public int Population; public int ActualFood; public GameObject canvas; // Referenz auf das Canvas-Objekt public Text[] texts; // Array der Text-Objekte private int[] Array = new int[7]; // Start is called before the first frame update void Start() { for (int i = 0; i < objectsToDeactivate.Length; i++) { objectsToDeactivate[i].SetActive(false); // deactivate the game object } for (int i = 0; i < objectsToActivate.Length; i++) { objectsToActivate[i].SetActive(true); // activate the game object } Array[0] = Industry; Array[1] = Wealth; Array[2] = Science; Array[3] = Food; Array[4] = MilitaryPower; Array[5] = Population; Array[6] = ActualFood; } public void SetPositionCenter() { transform.position = canvas.transform.position; // Position des Hauptobjekts } void Update() { Array[0] = Industry; Array[1] = Wealth; Array[2] = Science; Array[3] = Food; Array[4] = MilitaryPower; Array[5] = Population; Array[6] = ActualFood; for (int i = 0; i < 7; i++) { int temp = Array[i]; if (temp / 1000000 >= 1) { temp /= 1000000; texts[i].text = temp.ToString() + " M"; } else if (temp / 1000 >= 1) { temp /= 1000; texts[i].text = temp.ToString() + " K"; } else { texts[i].text = Array[i].ToString(); } } } // Get Methodes, so it will search in all the planets in the solar system to get recours public int GetFood(int id) { int food = 0; if (Planets != null) { for (int i = 0; i < Planets.Length; i++) { if (Planets[i].GetComponent().PlayerID == id) { food += Planets[i].GetComponent().food; } } } return food; } public int GetScience(int id) { int science = 0; if (Planets != null) { for (int i = 0; i < Planets.Length; i++) { if (Planets[i].GetComponent().PlayerID == id) { science += Planets[i].GetComponent().science; } } } return science; } public int GetPower(int id) { int power = 0; if (Planets != null) { for (int i = 0; i < Planets.Length; i++) { if (Planets[i].GetComponent().PlayerID == id) { power += Planets[i].GetComponent().power; } } } return power; } public int GetMoney(int id) { int money = 0; if (Planets != null) { for (int i = 0; i < Planets.Length; i++) { if (Planets[i].GetComponent().PlayerID == id) { money += Planets[i].GetComponent().money; } } } return money; } public int GetIndustrialCapacity(int id) { int industrialCapacity = 0; if (Planets != null) { for (int i = 0; i < Planets.Length; i++) { if (Planets[i].GetComponent().PlayerID == id) { industrialCapacity += Planets[i].GetComponent().industrialCapacity; } } } return industrialCapacity; } public int GetPopulation(int id) { int population = 0; if (Planets != null) { for (int i = 0; i < Planets.Length; i++) { if (Planets[i].GetComponent().PlayerID == id) { population += Planets[i].GetComponent().population; } } } return population; } public int GetActualFood(int id) { int actualFood = 0; if(Planets != null) { for (int i = 0; i < Planets.Length; i++) { if (Planets[i].GetComponent().PlayerID == id) { actualFood += Planets[i].GetComponent().actualFood; } } } return actualFood; } public void UpdateFood(int id , int FoodLvlScience) { if (Planets != null) { for (int i = 0; i < Planets.Length; i++) { if (Planets[i].GetComponent().PlayerID == id) { Planets[i].GetComponent().UpdateFood(FoodLvlScience); } } } } public void SetIDPlanet(int PlayerID, int PlanetID) { Planets[PlanetID].GetComponent().PlayerID = PlayerID; } }