using System; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UIElements; using static UnityEngine.Rendering.DebugUI; public class GameOver : MonoBehaviour { [Header("UI and HUB")] [SerializeField] GameObject deathPanel; private float duration = 4f; [SerializeField] public float timer; [SerializeField] TMP_Text deathTime; [SerializeField] public TMP_Text infoText; [SerializeField] public TMP_Text GameStateText; [SerializeField] public GameObject retryButton; [SerializeField] public GameObject costField; [SerializeField] TMP_Text costText; [SerializeField] int cost; //[SerializeField] public bool recentDeath; //discaraded [SerializeField] GameObject levelScript; [SerializeField] public bool timerOn; public float etwas; public float zeit; [Header("ScriptPile")] [SerializeField] GameObject scriptPile; [SerializeField] GameObject eFie; [SerializeField] GameObject eSilv; [SerializeField] GameObject eHai; InventoryScript inventory; ChangeHealth healthScript; HandleEnergy battery; FieScript fie; SilvScript silv; HaiScript hai; LevelBehavior level; private void Awake() { inventory = scriptPile.GetComponent(); healthScript = scriptPile.GetComponent(); battery = scriptPile.GetComponent(); fie = eFie.GetComponent(); hai = eHai.GetComponent(); silv = eSilv.GetComponent(); level = levelScript.GetComponent(); } void Start() { timer = 10f; inventory.Gems = 599; deathPanel.SetActive(false); } void Update() { if (level.gameWon == true) { CheckWinTime(); } else { CheckDeathTime(); } } public void ShowDeathScreen() { //Time.timeScale = 0; timerOn = true; timer = 10f; deathPanel.SetActive(true); retryButton.SetActive(true); costField.SetActive(true); LeanTween.scale(deathPanel, transform.localScale * 1f, duration * Time.deltaTime).setDelay(.1f).setEase(LeanTweenType.easeOutBounce); SpeakEnemy(); costText.text = cost.ToString(); //ZUM DEBUGGEN CheckDeathTime(); //OPTION INS MAINMENUE ZURÜCKZUKEHREN } public void ShowWinScreen() { Debug.Log("Gut gemacht"); StopEnemies(); timerOn = true; timer = 10f; deathPanel.SetActive(true); LeanTween.scale(deathPanel, transform.localScale * 1f, duration * Time.deltaTime).setDelay(.1f).setEase(LeanTweenType.easeOutBounce); CheckWinTime(); GameStateText.text = "You won!"; infoText.text = "You earned " + level.earnedGems + " Gems!"; retryButton.SetActive(false); costField.SetActive(false); } public void GiveNewChance() { if (inventory.Gems >= cost) { NewChance(); inventory.Gems -= cost; Debug.Log(inventory.Gems); timerOn = false; timer = 10f; } else //EINBAUEN, DASS MAN DORT GEMS KAUFEN KANN { infoText.text = "You don´t have enough gems to do that."; } } public void StopBothering() { //Time.timeScale = 1; //UNSICHER OB LADEN VON SCENE DEN WERT AUTO. AUF 1 SETZT //ausgebaut Debug.Log("Jetzt würdest du wieder in die MainMenueScene geschmissen werden"); SceneManager.LoadSceneAsync(0); } public void NewChance() { inventory.Health = inventory.StandardHealth; if (inventory.StandardEnergy >= (inventory.Energy + battery.addEnergyValue)) { inventory.Energy += battery.addEnergyValue; } LeanTween.scale(deathPanel, transform.localScale * 0f, duration * Time.deltaTime).setDelay(.1f).setEase(LeanTweenType.easeOutBounce); deathPanel.SetActive(false); //Time.timeScale = 1; //Logik: bei Retry, soll der Player nochmal neue Energie bekommen fie.StartStuff(); silv.StartStuff(); hai.StartStuff(); level.gameOngoing = true; } public void CheckDeathTime() { if(timerOn == true) { timer += zeit - Time.deltaTime; deathTime.text = Convert.ToInt32(timer).ToString(); if (timer <= 0.0f) { StopBothering(); timerOn = false; timer = 10f; } } } public void CheckWinTime() { if (timerOn == true) { timer += zeit - Time.deltaTime; deathTime.text = Convert.ToInt32(timer).ToString(); if (timer <= 0.0f) { timerOn = false; timer = 10f; Debug.Log("Next up: SwitchScene()"); level.SwitchScene(); Debug.Log("Just swapped scripts"); } } } public void CalculateCost() { cost = healthScript.deathCounter * 100; if (cost == 300) { infoText.text = "You must really like being here."; } if (cost >= 1000) { cost = 900; infoText.text = "But you refused."; } } public void SpeakEnemy() { if (fie.fieKill) { infoText.text = "HAAHAHAHAHAAHAHAHAHAHAHAHAHA"; } if (silv.silvKill) { infoText.text = "Oh no, I accidently killed someone again. I'm sowy. I just wanted to hug you :("; } if (hai.haiKill) { infoText.text = "You sound great..."; } else { infoText.text = "Try again?"; } } public void StopEnemies() { fie.StopAllCoroutines(); silv.StopAllCoroutines(); hai.StopAllCoroutines(); } }