Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections.Generic;
- public class BuildingManager : MonoBehaviour
- {
- [Header("Panels: ")]
- public GameObject buyBuildingPanel;
- public List<GameObject> panels = new List<GameObject>();
- [Header("Other: ")]
- [SerializeField] private int finishBuilding;
- [SerializeField] private JaoderNeinTurm humanscript;
- private GameObject whichBuildingPanel;
- private GameObject whichBuildingPrefab;
- private GameObject brokenHouse;
- public int preis;
- private float timer = 0;
- private bool buildingAllowed = false;
- [HideInInspector] public bool raycastAllowed = true;
- private Vector3 brokenHousePosition;
- BuyBrokeHause BuyBrokeHause;
- void Start()
- {
- BuyBrokeHause = FindObjectOfType<BuyBrokeHause>();
- foreach (GameObject panel in panels)
- {
- panel.SetActive(false);
- }
- }
- void Update()
- {
- if(buildingAllowed)
- {
- timer += Time.deltaTime;
- if(timer >= finishBuilding)
- {
- Instantiate(whichBuildingPrefab, brokenHousePosition, Quaternion.identity);
- buildingAllowed = false;
- raycastAllowed = true;
- timer = 0;
- humanscript.FindHouseScript();
- }
- } else
- {
- if(raycastAllowed)
- {
- if (Input.GetMouseButtonDown(0))
- {
- Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
- RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
- if(hit.collider != null)
- {
- if (hit.transform.tag == "DestroyHouse")
- {
- buyBuildingPanel.SetActive(true);
- brokenHouse = hit.transform.gameObject;
- brokenHousePosition = brokenHouse.transform.position;
- raycastAllowed = false;
- Buy();
- } else if(hit.transform.tag == "Haus")
- {
- hit.transform.gameObject.GetComponent<OpenPanel>().OpenAPanel();
- }
- }
- }
- }
- }
- }
- public void Buy()
- {
- //int coins = PlayerPrefs.GetInt("Coins");
- BuyBrokeHause.Coins -= preis;
- PlayerPrefs.SetInt("Coins", BuyBrokeHause.Coins);
- }
- public void BuyBuilding(GameObject panel)
- {
- if(panel.activeSelf)
- {
- whichBuildingPanel = null;
- panel.SetActive(false);
- raycastAllowed = true;
- } else
- {
- whichBuildingPanel = panel;
- buyBuildingPanel.SetActive(false);
- panel.SetActive(true);
- }
- }
- public void WhichBuilding(GameObject building)
- {
- whichBuildingPanel.SetActive(false);
- whichBuildingPanel = null;
- whichBuildingPrefab = building;
- buildingAllowed = true;
- Destroy(brokenHouse);
- brokenHouse = null;
- }
- public void OpenPanel(GameObject panel)
- {
- if(panel.activeSelf)
- {
- panel.SetActive(false);
- raycastAllowed = true;
- } else
- {
- panel.SetActive(true);
- raycastAllowed = false;
- }
- }
- }
- -----------------------------------------------------------------------------------------------------
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class JaoderNeinTurm : MonoBehaviour
- {
- [SerializeField] private Vector3 desiredPosition;
- [SerializeField] private float speed;
- [SerializeField] private GameObject einreisePanel;
- [SerializeField] private Text nameText;
- [SerializeField] private Image menschImage;
- [SerializeField] private Transform scrollContainer;
- [SerializeField] private List<Sprite> menschenSprites = new List<Sprite>();
- [Header("Karten Prefabs: ")]
- [SerializeField] private GameObject mensch1;
- private bool move = false;
- private bool alreadyIn = false;
- private bool raycastAllowed = false;
- private GameObject human;
- private GameObject specificHuman;
- [SerializeField] private List<HausGebäude> hausScripts = new List<HausGebäude>();
- private HausGebäude hausScript;
- private int index;
- void Start()
- {
- index = 0;
- hausScripts = new List<HausGebäude>(GameObject.FindObjectsOfType<HausGebäude>());
- hausScript = hausScripts[0];
- }
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
- RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
- if (hit.collider != null)
- {
- if (hit.transform.tag == "Mensch" && hit.transform.gameObject == specificHuman)
- {
- if (hit.transform.gameObject.name.Contains("People"))
- {
- nameText.text = "Tommy";
- menschImage.sprite = menschenSprites[0];
- }
- einreisePanel.SetActive(true);
- human = hit.transform.gameObject;
- raycastAllowed = false;
- }
- }
- }
- if (move)
- {
- if (Mathf.Abs(human.transform.position.x) < Mathf.Abs(desiredPosition.x))
- {
- human.transform.position += Vector3.left * speed * Time.deltaTime;
- }
- else
- {
- Destroy(human);
- move = false;
- }
- }
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (other.CompareTag("Mensch"))
- {
- specificHuman = other.gameObject;
- raycastAllowed = true;
- }
- }
- private void OnTriggerExit2D(Collider2D other)
- {
- if (other.CompareTag("Mensch"))
- {
- specificHuman = null;
- raycastAllowed = false;
- }
- }
- public void Einreise()
- {
- if (hausScript.menschen < 5)
- {
- print("2");
- if (human.name.Contains("People"))
- {
- print("3");
- hausScript.menschen++;
- hausScript.menschenList.Add(human.name);
- hausScript.humanImages.Add(menschenSprites[0]);
- //human.GetComponent<EnemyMove>().enabled = true;
- Instantiate(mensch1, scrollContainer);
- einreisePanel.SetActive(false);
- }
- else
- {
- index++;
- FindScript();
- }
- }
- else
- {
- // 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.
- print(hausScript.menschen);
- }
- }
- public void Abgelehnt()
- {
- move = true;
- einreisePanel.SetActive(false);
- }
- void FindScript()
- {
- if (hausScripts.Count > index)
- {
- hausScript = hausScripts[index];
- Einreise();
- }
- else
- {
- // Es gibt keine leeren Häuser mehr!!!
- print("NOOOO2");
- print(hausScript.menschen);
- }
- }
- public void FindHouseScript()
- {
- hausScripts = new List<HausGebäude>(GameObject.FindObjectsOfType<HausGebäude>());
- if (hausScripts != null)
- {
- hausScript = hausScripts[1];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement