Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Planet :MonoBehaviour {
- int[,] fields;
- public Sprite image;
- public string name;
- // Rohstoffvariablen definieren
- int TitanCapacity = 2000;
- public float Titan = 0;
- float DeltaTitan=1;
- Text titanInputField;
- int LithiumCapacity = 2000;
- public float Lithium = 0;
- float DeltaLithium = 0;
- Text lithiumInputField;
- int HydrogenCapacity = 2000;
- public float Hydrogen = 0;
- float DeltaHydrogen = 0;
- Text hydrogenInputField;
- int EnergyCapacity = 2000;
- public float Energy = 0;
- float DeltaEnergy = 0;
- Text energyInputField;
- // Use this for initialization
- public Planet(string Name) {
- int minFields = Random.Range(1, 5);
- int maxFields = Random.Range(1, 5);
- this.fields = new int[minFields, maxFields];
- Debug.Log("Planet Generiert");
- Sprite[] Spritearray = Resources.LoadAll<Sprite>("Textures/Planets");
- this.image = Spritearray[Random.Range(0, Spritearray.Length)];
- this.name = Name;
- Debug.Log(float.Parse(Name));
- AddTitan(float.Parse(Name));
- }
- public void Load() {
- int dummy = 0;
- //Planetenbild laden
- GameObject.Find("imagePlanet").GetComponent<Image>().sprite = this.image;
- //Rohstoffbestände laden
- dummy = (int)Mathf.Floor(this.Titan);
- titanInputField = GameObject.Find("Ti").GetComponent<Text>();
- titanInputField.text = dummy.ToString();
- dummy = (int)Mathf.Floor(this.Lithium);
- lithiumInputField = GameObject.Find("Li").GetComponent<Text>();
- lithiumInputField.text = dummy.ToString();
- dummy = (int)Mathf.Floor(this.Hydrogen);
- hydrogenInputField = GameObject.Find("H2").GetComponent<Text>();
- hydrogenInputField.text = dummy.ToString();
- dummy = (int)Mathf.Floor(this.Energy);
- energyInputField = GameObject.Find("NRG").GetComponent<Text>();
- energyInputField.text = dummy.ToString();
- Debug.Log(DeltaTitan);
- StartCoroutine(CalculateResources());
- }
- // Update is called once per frame
- void Update() {
- }
- //Oberfläche des Planeten würfeln
- void RandomizeSurface() {
- }
- //Ressourcenmanagement
- IEnumerator CalculateResources() {
- Debug.Log(DeltaTitan);
- while (true)
- {
- AddTitan(DeltaTitan);
- AddLithium(DeltaLithium);
- AddHydrogen(DeltaHydrogen);
- AddEnergy(DeltaEnergy);
- RefreshResourceInputFields();
- yield return new WaitForSeconds(1f);
- Debug.Log(DeltaTitan);
- }
- }
- void RefreshResourceInputFields() {
- titanInputField.text = Titan.ToString();
- lithiumInputField.text = Lithium.ToString();
- hydrogenInputField.text = Hydrogen.ToString();
- energyInputField.text = Energy.ToString();
- }
- void AddTitan(float amount)
- {
- if (amount + this.Titan > this.TitanCapacity)
- {
- this.Titan = this.TitanCapacity;
- }
- else
- {
- this.Titan = amount + this.Titan;
- }
- }
- void AddLithium(float amount)
- {
- if (amount + this.Lithium > this.LithiumCapacity)
- {
- this.Lithium = this.LithiumCapacity;
- }
- else
- {
- this.Lithium = amount + this.Lithium;
- }
- }
- void AddHydrogen(float amount)
- {
- if (amount + this.Hydrogen > this.HydrogenCapacity)
- {
- this.Hydrogen = this.HydrogenCapacity;
- }
- else
- {
- this.Hydrogen = amount + this.Hydrogen;
- }
- }
- void AddEnergy(float amount)
- {
- if (amount + this.Energy > this.EnergyCapacity)
- {
- this.Energy = this.EnergyCapacity;
- }
- else
- {
- this.Energy = amount + this.Energy;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement