RiftMayhem/Assets/Scripts/Player/PlayerDeathVFXManager.cs
Pedro Gomes 2773ef7d6e Player Death Update
- Players can now die (finally)
- Solo players have a single cheat death per scene (reviving automatically after the first death)
- group players have revive mechanic, where a player faints when his health gets to 0, creating a revive circle around him, other players can stand on it to revive him. if after x seconds they don't get revived they bleed out and stay perma death until scene changes or all players die
- Multiple VFX added using post processing for cheat death, fainting, reviving, and perma death events.
- stopped players from moving and pressing keys when dead
- enemies now change target if they try to attack a dead/fainted target.
2024-07-20 19:49:14 +01:00

134 lines
3.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerDeathVFXManager : MonoBehaviour
{
[Header("TextOverlay:")]
[SerializeField] private GameObject cheatedDeathText;
[SerializeField] private GameObject revivedText;
[SerializeField] private GameObject faintedText;
[SerializeField] private GameObject permaDeathText;
[Header("Volumes:")]
[SerializeField] private PlayerDeathVFX cheatedDeathVFX;
[SerializeField] private PlayerDeathVFX faintedVFX;
[SerializeField] private PlayerDeathVFX permaDeathVFX;
[Header("Listeners:")]
[SerializeField] private GameEventListener onLocalPlayerCheatedDeath;
[SerializeField] private GameEventListener onLocalPlayerFainted;
[SerializeField] private GameEventListener onLocalPlayerPermaDeath;
[SerializeField] private GameEventListener onLocalPlayerRevived;
[SerializeField] private GameEventListener_ZoneData onGameSceneLoaded;
private void Awake()
{
onLocalPlayerCheatedDeath.Response.AddListener(OnLocalCheatedDeath);
onLocalPlayerFainted.Response.AddListener(OnLocalFainted);
onLocalPlayerPermaDeath.Response.AddListener(OnLocalPermaDeath);
onLocalPlayerRevived.Response.AddListener(OnLocalPlayerRevived);
onGameSceneLoaded.Response.AddListener((x) => ResetAll());
}
private void ResetAll()
{
cheatedDeathVFX.ResetWeight();
faintedVFX.ResetWeight();
permaDeathVFX.ResetWeight();
cheatedDeathText.SetActive(false);
faintedText.SetActive(false);
permaDeathText.SetActive(false);
revivedText.SetActive(false);
}
private void OnLocalCheatedDeath()
{
EnableCheatedDeathVFX();
faintedVFX.ResetWeight();
permaDeathVFX.ResetWeight();
faintedText.SetActive(false);
permaDeathText.SetActive(false);
revivedText.SetActive(false);
StartCoroutine(FallbackCheatedDeathVFX());
}
IEnumerator FallbackCheatedDeathVFX()
{
yield return new WaitForSeconds(GameConstants.CharacterBalancing.SoloCheatDeathInvulnerabilityDuration);
DisableCheatedDeathVFX();
}
private void OnLocalFainted()
{
cheatedDeathVFX.ResetWeight();
EnableFaintedVFX();
permaDeathVFX.ResetWeight();
cheatedDeathText.SetActive(false);
permaDeathText.SetActive(false);
revivedText.SetActive(false);
}
private void OnLocalPermaDeath()
{
cheatedDeathVFX.ResetWeight();
faintedVFX.ResetWeight();
EnablePermaDeathVFX();
cheatedDeathText.SetActive(false);
faintedText.SetActive(false);
revivedText.SetActive(false);
}
private void OnLocalPlayerRevived()
{
EnableCheatedDeathVFX();
faintedVFX.ResetWeight();
permaDeathVFX.ResetWeight();
revivedText.SetActive(true);
cheatedDeathText.SetActive(false);
faintedText.SetActive(false);
permaDeathText.SetActive(false);
StartCoroutine(FallbackCheatedDeathVFX());
}
public void EnableCheatedDeathVFX()
{
cheatedDeathVFX.BlendIn();
cheatedDeathText.SetActive(true);
}
public void DisableCheatedDeathVFX()
{
cheatedDeathVFX.BlendOut();
cheatedDeathText.SetActive(false);
revivedText.SetActive(false);
}
public void EnableFaintedVFX()
{
faintedVFX.BlendIn();
faintedText.SetActive(true);
}
public void DisableFaintedVFX()
{
faintedVFX.BlendOut();
faintedText.SetActive(false);
}
public void EnablePermaDeathVFX()
{
permaDeathVFX.BlendIn();
permaDeathText.SetActive(true);
}
public void DisablePermaDeathVFX()
{
permaDeathVFX.BlendOut();
permaDeathText.SetActive(false);
}
}