Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Planet :MonoBehaviour {
  7.  
  8. int[,] fields;
  9. public Sprite image;
  10. public string name;
  11. // Rohstoffvariablen definieren
  12. int TitanCapacity = 2000;
  13. public float Titan = 0;
  14. float DeltaTitan=1;
  15. Text titanInputField;
  16. int LithiumCapacity = 2000;
  17. public float Lithium = 0;
  18. float DeltaLithium = 0;
  19. Text lithiumInputField;
  20. int HydrogenCapacity = 2000;
  21. public float Hydrogen = 0;
  22. float DeltaHydrogen = 0;
  23. Text hydrogenInputField;
  24. int EnergyCapacity = 2000;
  25. public float Energy = 0;
  26. float DeltaEnergy = 0;
  27. Text energyInputField;
  28.  
  29. // Use this for initialization
  30. public Planet(string Name) {
  31. int minFields = Random.Range(1, 5);
  32. int maxFields = Random.Range(1, 5);
  33. this.fields = new int[minFields, maxFields];
  34. Debug.Log("Planet Generiert");
  35.  
  36. Sprite[] Spritearray = Resources.LoadAll<Sprite>("Textures/Planets");
  37. this.image = Spritearray[Random.Range(0, Spritearray.Length)];
  38. this.name = Name;
  39. Debug.Log(float.Parse(Name));
  40. AddTitan(float.Parse(Name));
  41.  
  42. }
  43.  
  44. public void Load() {
  45. int dummy = 0;
  46. //Planetenbild laden
  47. GameObject.Find("imagePlanet").GetComponent<Image>().sprite = this.image;
  48. //Rohstoffbestände laden
  49. dummy = (int)Mathf.Floor(this.Titan);
  50. titanInputField = GameObject.Find("Ti").GetComponent<Text>();
  51. titanInputField.text = dummy.ToString();
  52. dummy = (int)Mathf.Floor(this.Lithium);
  53. lithiumInputField = GameObject.Find("Li").GetComponent<Text>();
  54. lithiumInputField.text = dummy.ToString();
  55. dummy = (int)Mathf.Floor(this.Hydrogen);
  56. hydrogenInputField = GameObject.Find("H2").GetComponent<Text>();
  57. hydrogenInputField.text = dummy.ToString();
  58. dummy = (int)Mathf.Floor(this.Energy);
  59. energyInputField = GameObject.Find("NRG").GetComponent<Text>();
  60. energyInputField.text = dummy.ToString();
  61. Debug.Log(DeltaTitan);
  62. StartCoroutine(CalculateResources());
  63. }
  64.  
  65. // Update is called once per frame
  66. void Update() {
  67.  
  68. }
  69.  
  70.  
  71. //Oberfläche des Planeten würfeln
  72. void RandomizeSurface() {
  73.  
  74. }
  75.  
  76.  
  77. //Ressourcenmanagement
  78.  
  79. IEnumerator CalculateResources() {
  80. Debug.Log(DeltaTitan);
  81. while (true)
  82. {
  83. AddTitan(DeltaTitan);
  84. AddLithium(DeltaLithium);
  85. AddHydrogen(DeltaHydrogen);
  86. AddEnergy(DeltaEnergy);
  87. RefreshResourceInputFields();
  88. yield return new WaitForSeconds(1f);
  89. Debug.Log(DeltaTitan);
  90. }
  91. }
  92.  
  93. void RefreshResourceInputFields() {
  94. titanInputField.text = Titan.ToString();
  95. lithiumInputField.text = Lithium.ToString();
  96. hydrogenInputField.text = Hydrogen.ToString();
  97. energyInputField.text = Energy.ToString();
  98. }
  99.  
  100. void AddTitan(float amount)
  101. {
  102. if (amount + this.Titan > this.TitanCapacity)
  103. {
  104. this.Titan = this.TitanCapacity;
  105. }
  106. else
  107. {
  108. this.Titan = amount + this.Titan;
  109. }
  110. }
  111. void AddLithium(float amount)
  112. {
  113. if (amount + this.Lithium > this.LithiumCapacity)
  114. {
  115. this.Lithium = this.LithiumCapacity;
  116. }
  117. else
  118. {
  119. this.Lithium = amount + this.Lithium;
  120. }
  121. }
  122. void AddHydrogen(float amount)
  123. {
  124. if (amount + this.Hydrogen > this.HydrogenCapacity)
  125. {
  126. this.Hydrogen = this.HydrogenCapacity;
  127. }
  128. else
  129. {
  130. this.Hydrogen = amount + this.Hydrogen;
  131. }
  132. }
  133. void AddEnergy(float amount)
  134. {
  135. if (amount + this.Energy > this.EnergyCapacity)
  136. {
  137. this.Energy = this.EnergyCapacity;
  138. }
  139. else
  140. {
  141. this.Energy = amount + this.Energy;
  142. }
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement