141 lines
3.3 KiB
C#
141 lines
3.3 KiB
C#
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] TMP_Text costText;
|
||
[SerializeField] int cost;
|
||
//[SerializeField] public bool recentDeath; //discaraded
|
||
|
||
[SerializeField] public bool timerOn;
|
||
|
||
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()
|
||
{
|
||
timer = 10f;
|
||
inventory.Gems = 599;
|
||
deathPanel.SetActive(false);
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
|
||
CheckDeathTime();
|
||
//if (Time.timeScale == 1)
|
||
//{
|
||
// Debug.Log("The game is running.");
|
||
//}
|
||
//else if(Time.timeScale == 0)
|
||
//{
|
||
// Debug.Log("The game should be paused now.");
|
||
//}
|
||
}
|
||
|
||
public void ShowDeathScreen()
|
||
{
|
||
//Time.timeScale = 0;
|
||
timerOn = true;
|
||
timer = 10f;
|
||
deathPanel.SetActive(true);
|
||
infoText.text = "Try again?";
|
||
costText.text = cost.ToString(); //ZUM DEBUGGEN
|
||
CheckDeathTime();
|
||
|
||
//OPTION INS MAINMENUE ZURÜCKZUKEHREN
|
||
}
|
||
|
||
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
|
||
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;
|
||
}
|
||
|
||
deathPanel.SetActive(false);
|
||
//Time.timeScale = 1;
|
||
|
||
//Logik: bei Retry, soll der Player nochmal neue Energie bekommen
|
||
|
||
}
|
||
|
||
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 CalculateCost()
|
||
{
|
||
cost = healthScript.deathCounter * 100;
|
||
}
|
||
}
|