58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.SceneManagement;
|
||
|
||
public class GrandePorteState : MonoBehaviour
|
||
{
|
||
public DoorHealthBarManager dhbManager;
|
||
public int health = 100;
|
||
private bool isSlightlyDamaged;
|
||
private bool isSeverelyDamaged;
|
||
private bool isDestroyed;
|
||
|
||
public void TakeDamage(int damage)
|
||
{
|
||
health -= damage;
|
||
dhbManager.UpdateHealthValue(health);
|
||
if (health <= 0)
|
||
{
|
||
if(isDestroyed == false)
|
||
{
|
||
isDestroyed = true;
|
||
PopupUI popup = GameObject.FindGameObjectWithTag("Popup").GetComponent<PopupUI>();
|
||
popup.SetPopup("Porte détruite!", true);
|
||
// TODO: SOLUTION TEMPORAIRE POUR LA DÉMO – Supprimer les lignes suivantes du if et gérer la défaite dans le GameManager
|
||
popup.SetPopup("Tout est perdu!", true);
|
||
StartCoroutine(RestartDelay());
|
||
}
|
||
|
||
onDestroyDoor();
|
||
}
|
||
else if (health <= 33 && isSeverelyDamaged == false)
|
||
{
|
||
isSeverelyDamaged = true;
|
||
PopupUI popup = GameObject.FindGameObjectWithTag("Popup").GetComponent<PopupUI>();
|
||
popup.SetPopup("Porte gravement endommagée!", true);
|
||
}
|
||
else if (health <= 66 && isSlightlyDamaged == false)
|
||
{
|
||
isSlightlyDamaged = true;
|
||
PopupUI popup = GameObject.FindGameObjectWithTag("Popup").GetComponent<PopupUI>();
|
||
popup.SetPopup("Porte endommagée!", true);
|
||
}
|
||
}
|
||
|
||
private void onDestroyDoor()
|
||
{
|
||
Debug.Log("GAME OVER");
|
||
}
|
||
|
||
// TODO: SOLUTION TEMPORAIRE POUR LA DÉMO – Supprimer cette fonction et gérer la défaite dans le GameManager
|
||
private IEnumerator RestartDelay()
|
||
{
|
||
yield return new WaitForSeconds(10);
|
||
GameManager.Instance.ReloadScene();
|
||
}
|
||
}
|