Advertisement
xxsmarioxxs

Untitled

Mar 31st, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.11 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. public class BuildingManager : MonoBehaviour
  5. {
  6. [Header("Panels: ")]
  7. public GameObject buyBuildingPanel;
  8. public List<GameObject> panels = new List<GameObject>();
  9.  
  10. [Header("Other: ")]
  11. [SerializeField] private int finishBuilding;
  12. [SerializeField] private JaoderNeinTurm humanscript;
  13.  
  14. private GameObject whichBuildingPanel;
  15. private GameObject whichBuildingPrefab;
  16. private GameObject brokenHouse;
  17. public int preis;
  18. private float timer = 0;
  19. private bool buildingAllowed = false;
  20. [HideInInspector] public bool raycastAllowed = true;
  21. private Vector3 brokenHousePosition;
  22. BuyBrokeHause BuyBrokeHause;
  23.  
  24. void Start()
  25. {
  26. BuyBrokeHause = FindObjectOfType<BuyBrokeHause>();
  27. foreach (GameObject panel in panels)
  28. {
  29. panel.SetActive(false);
  30. }
  31. }
  32.  
  33. void Update()
  34. {
  35. if(buildingAllowed)
  36. {
  37. timer += Time.deltaTime;
  38. if(timer >= finishBuilding)
  39. {
  40. Instantiate(whichBuildingPrefab, brokenHousePosition, Quaternion.identity);
  41. buildingAllowed = false;
  42. raycastAllowed = true;
  43. timer = 0;
  44. humanscript.FindHouseScript();
  45. }
  46. } else
  47. {
  48. if(raycastAllowed)
  49. {
  50. if (Input.GetMouseButtonDown(0))
  51. {
  52. Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  53. Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
  54.  
  55. RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
  56. if(hit.collider != null)
  57. {
  58. if (hit.transform.tag == "DestroyHouse")
  59. {
  60. buyBuildingPanel.SetActive(true);
  61. brokenHouse = hit.transform.gameObject;
  62. brokenHousePosition = brokenHouse.transform.position;
  63. raycastAllowed = false;
  64. Buy();
  65. } else if(hit.transform.tag == "Haus")
  66. {
  67. hit.transform.gameObject.GetComponent<OpenPanel>().OpenAPanel();
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. public void Buy()
  75. {
  76. //int coins = PlayerPrefs.GetInt("Coins");
  77. BuyBrokeHause.Coins -= preis;
  78. PlayerPrefs.SetInt("Coins", BuyBrokeHause.Coins);
  79. }
  80. public void BuyBuilding(GameObject panel)
  81. {
  82. if(panel.activeSelf)
  83. {
  84. whichBuildingPanel = null;
  85. panel.SetActive(false);
  86. raycastAllowed = true;
  87.  
  88. } else
  89. {
  90. whichBuildingPanel = panel;
  91. buyBuildingPanel.SetActive(false);
  92. panel.SetActive(true);
  93. }
  94. }
  95.  
  96. public void WhichBuilding(GameObject building)
  97. {
  98. whichBuildingPanel.SetActive(false);
  99. whichBuildingPanel = null;
  100. whichBuildingPrefab = building;
  101. buildingAllowed = true;
  102. Destroy(brokenHouse);
  103. brokenHouse = null;
  104. }
  105.  
  106. public void OpenPanel(GameObject panel)
  107. {
  108. if(panel.activeSelf)
  109. {
  110. panel.SetActive(false);
  111. raycastAllowed = true;
  112. } else
  113. {
  114. panel.SetActive(true);
  115. raycastAllowed = false;
  116. }
  117. }
  118.  
  119. }
  120.  
  121. -----------------------------------------------------------------------------------------------------
  122. using System.Collections;
  123. using System.Collections.Generic;
  124. using UnityEngine;
  125. using UnityEngine.UI;
  126.  
  127. public class JaoderNeinTurm : MonoBehaviour
  128. {
  129. [SerializeField] private Vector3 desiredPosition;
  130. [SerializeField] private float speed;
  131. [SerializeField] private GameObject einreisePanel;
  132. [SerializeField] private Text nameText;
  133. [SerializeField] private Image menschImage;
  134. [SerializeField] private Transform scrollContainer;
  135. [SerializeField] private List<Sprite> menschenSprites = new List<Sprite>();
  136. [Header("Karten Prefabs: ")]
  137. [SerializeField] private GameObject mensch1;
  138. private bool move = false;
  139. private bool alreadyIn = false;
  140. private bool raycastAllowed = false;
  141. private GameObject human;
  142. private GameObject specificHuman;
  143. [SerializeField] private List<HausGebäude> hausScripts = new List<HausGebäude>();
  144. private HausGebäude hausScript;
  145. private int index;
  146.  
  147. void Start()
  148. {
  149. index = 0;
  150. hausScripts = new List<HausGebäude>(GameObject.FindObjectsOfType<HausGebäude>());
  151. hausScript = hausScripts[0];
  152. }
  153.  
  154. void Update()
  155. {
  156. if (Input.GetMouseButtonDown(0))
  157. {
  158. Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  159. Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
  160.  
  161. RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
  162. if (hit.collider != null)
  163. {
  164. if (hit.transform.tag == "Mensch" && hit.transform.gameObject == specificHuman)
  165. {
  166. if (hit.transform.gameObject.name.Contains("People"))
  167. {
  168. nameText.text = "Tommy";
  169. menschImage.sprite = menschenSprites[0];
  170. }
  171. einreisePanel.SetActive(true);
  172. human = hit.transform.gameObject;
  173. raycastAllowed = false;
  174. }
  175. }
  176. }
  177. if (move)
  178. {
  179. if (Mathf.Abs(human.transform.position.x) < Mathf.Abs(desiredPosition.x))
  180. {
  181. human.transform.position += Vector3.left * speed * Time.deltaTime;
  182. }
  183. else
  184. {
  185. Destroy(human);
  186. move = false;
  187. }
  188. }
  189. }
  190.  
  191. private void OnTriggerEnter2D(Collider2D other)
  192. {
  193. if (other.CompareTag("Mensch"))
  194. {
  195. specificHuman = other.gameObject;
  196. raycastAllowed = true;
  197. }
  198. }
  199.  
  200. private void OnTriggerExit2D(Collider2D other)
  201. {
  202. if (other.CompareTag("Mensch"))
  203. {
  204. specificHuman = null;
  205. raycastAllowed = false;
  206. }
  207. }
  208.  
  209. public void Einreise()
  210. {
  211. if (hausScript.menschen < 5)
  212. {
  213. print("2");
  214. if (human.name.Contains("People"))
  215. {
  216. print("3");
  217. hausScript.menschen++;
  218. hausScript.menschenList.Add(human.name);
  219. hausScript.humanImages.Add(menschenSprites[0]);
  220. //human.GetComponent<EnemyMove>().enabled = true;
  221. Instantiate(mensch1, scrollContainer);
  222. einreisePanel.SetActive(false);
  223.  
  224. }
  225. else
  226. {
  227. index++;
  228. FindScript();
  229. }
  230. }
  231. else
  232. {
  233. // Es gibt gar keine Häuser!!! Hier kommt dann das hin, was dann passieren soll. Da du das dann ganz einfach bestimmen kannst, dieses Script sowieso schon zu anstrengend war und ich auch nicht, weiss, was du hier machen willst, kannst du es auch machen.
  234. print(hausScript.menschen);
  235. }
  236. }
  237.  
  238.  
  239. public void Abgelehnt()
  240. {
  241. move = true;
  242. einreisePanel.SetActive(false);
  243. }
  244.  
  245. void FindScript()
  246. {
  247. if (hausScripts.Count > index)
  248. {
  249. hausScript = hausScripts[index];
  250. Einreise();
  251. }
  252. else
  253. {
  254. // Es gibt keine leeren Häuser mehr!!!
  255. print("NOOOO2");
  256. print(hausScript.menschen);
  257. }
  258. }
  259.  
  260. public void FindHouseScript()
  261. {
  262. hausScripts = new List<HausGebäude>(GameObject.FindObjectsOfType<HausGebäude>());
  263. if (hausScripts != null)
  264. {
  265. hausScript = hausScripts[1];
  266. }
  267. }
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement