projet-massimo-pfe/PFE OmniVR/Assets/GrandePorteState.cs
jimmy tremblay-Bernier c1bf5a4ca1 initial commit
2022-03-12 22:04:30 -04:00

58 lines
1.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.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();
}
}