Files
ConvenientHorror/Assets/Scripts/Button Functions/GameOver.cs

126 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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] TMP_Text infoText;
[SerializeField] public bool recentDeath;
bool timerOn = false;
public float etwas;
public float zeit;
[Header("ScriptPile")]
[SerializeField] GameObject scriptPile;
InventoryScript inventory;
ChangeHealth healthScript;
HandleEnergy battery;
private void Awake()
{
inventory = scriptPile.GetComponent<InventoryScript>();
healthScript = scriptPile.GetComponent<ChangeHealth>();
battery = scriptPile.GetComponent<HandleEnergy>();
}
void Start()
{
recentDeath = false; //Eigentlicher Wert
deathPanel.SetActive(false);
recentDeath = true; //ZUM TESTEN
timer = 0;
}
void Update()
{
recentDeath = true;
if (recentDeath)
{
ShowDeathScreen();
CheckDeathTime();
timerOn = true;
}
}
public void ShowDeathScreen()
{
deathPanel.SetActive(true);
infoText.text = "Try again?";
infoText.text = inventory.Gems.ToString(); //ZUM DEBUGGEN
//OPTION INS MAINMENUE ZURÜCKZUKEHREN
}
public void GiveNewChance()
{
if (inventory.Gems > 100)
{
NewChance();
inventory.Gems -= 100;
}
else //EINBAUEN, DASS MAN DORT GEMS KAUFEN KANN
{
infoText.text = "You don´t have enough gems to do that.";
}
}
public void StopBothering()
{
recentDeath = false;
Time.timeScale = 1; //UNSICHER OB LADEN VON SCENE DEN WERT AUTO. AUF 1 SETZT
Debug.Log("Jetzt würdest du wieder in die MainMenueScene geschmissen werden");
//SceneManager.LoadSceneAsync(0); //MUSS AM ENDE WIEDER EINGEBAUT WERDEN
}
public void NewChance()
{
inventory.Health = healthScript.standardHealth;
if (battery.standardEnergy >= (inventory.Energy + battery.addEnergyValue))
{
inventory.Energy += battery.addEnergyValue;
}
//Logik: bei Retry, soll der Player nochmal neue Energie bekommen
}
public void CheckDeathTime()
{
if(timerOn == true)
{
timer = 10;
zeit -= Time.deltaTime;
deathTime.text = Convert.ToInt32(zeit + timer).ToString();
if (zeit >= timer)
{
recentDeath = false;
StopBothering();
timerOn = false;
}
}
}
}