Health and Energy Logic ausgeführt, GameOver und LevelTime Scripte angelegt, Timer (aber keinen krassen coolen) eingebaut
This commit is contained in:
82
Assets/Scripts/Button Functions/GameOver.cs
Normal file
82
Assets/Scripts/Button Functions/GameOver.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
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] float timer;
|
||||
[SerializeField] TMP_Text deathTime;
|
||||
[SerializeField] bool recentDeath;
|
||||
|
||||
[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()
|
||||
{
|
||||
deathPanel.SetActive(false);
|
||||
recentDeath = true;
|
||||
timer = 10;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (recentDeath)
|
||||
{
|
||||
deathTime.text = Convert.ToInt32(timer -= Time.deltaTime).ToString();
|
||||
|
||||
if(timer >= 0)
|
||||
{
|
||||
StopBothering();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StopBothering();
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowDeathScreen()
|
||||
{
|
||||
deathPanel.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
public void StopBothering()
|
||||
{
|
||||
recentDeath = false;
|
||||
Time.timeScale = 1; //UNSICHER OB LAden VON SCENE DEN WERT AUTO. AUF 1 SETZT
|
||||
SceneManager.LoadSceneAsync(0);
|
||||
}
|
||||
|
||||
|
||||
public void NewChance()
|
||||
{
|
||||
inventory.Health = healthScript.standardHealth;
|
||||
|
||||
if (battery.standardEnergy <= (inventory.Energy + battery.addEnergyValue))
|
||||
{
|
||||
inventory.Energy += battery.addEnergyValue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user